Skip to content

Commit 622e8c3

Browse files
authored
fix: stop an app's codegenConfig from hijacking this library's codegen (#201)
## Problem When an app adds a TurboModule of its own and puts `codegenConfig` in its root package.json, that config is applied to this library's codegen instead of the library's own. `NativeCodePushSpec` is never generated, the app's spec is written into the library's build directory, and compilation fails: ``` node_modules/@bravemobile/react-native-code-push/android/app/src/main/java/ com/microsoft/codepush/react/CodePushNativeModule.java:44: error: cannot find symbol public class CodePushNativeModule extends NativeCodePushSpec { ``` The react-native gradle plugin's `findPackageJsonFile()` looks for `../package.json` next to the gradle module first and falls back to the app root when that file is missing. This library's module sat at `android/app`, so the first lookup never resolved and the app root was always read. It only stayed invisible while apps had no `codegenConfig` of their own. ## Fix The gradle module now lives at `android/`. The first lookup resolves to the library's own package.json, which already carries the correct `codegenConfig`. No second copy of the config is introduced, and this is the layout most React Native libraries already use. A separate commit removes the standalone gradle setup, which had stopped working long ago: the wrapper pinned Gradle 2.4, the buildscript classpath pinned AGP 1.3.0, `gradle.properties` was in a subproject directory where Gradle never reads it, and Android unit tests run through an example app. None of those files were reachable from any build. ## Upgrading An existing app holds an autolinking cache pointing at the old path, so the first build after upgrading fails: ``` Configuring project ':bravemobile_react-native-code-push' without an existing directory is not allowed. The configured projectDirectory '.../react-native-code-push/android/app' does not exist ``` Deleting these two directories clears it: ``` android/build/generated/autolinking android/app/build/generated/autolinking ``` Nothing else changes for consumers. The gradle project name stays `:bravemobile_react-native-code-push` because it is derived from the npm package name, and the apply path for `codepush-export.gradle` is untouched. ## Verification codegen, Java compilation, unit tests and the CMake native build all pass on the RN 0.77.3, 0.80.3, 0.83.2 and 0.86.0 example apps, covering both ends of the supported range. The reproduction case was checked on the lowest and highest versions: with `codegenConfig` present in the app root, `NativeCodePushSpec.java` is generated for the library and the app's own spec is generated for the app module, each in its own place.
1 parent 3c304b5 commit 622e8c3

47 files changed

Lines changed: 53 additions & 361 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Ankh.NoLoad
154154
Examples/testapp_rn
155155

156156
# Android debug build files (conflict ignoring #Visual Studio files)
157-
!android/app/src/debug/
157+
!android/src/debug/
158158

159159
# prevent CLI code ignored (ignored by "[Rr]elease*/")
160160
!cli/commands/releaseCommand/

‎android/app/build.gradle‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎android/build.gradle‎

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
1+
apply plugin: "com.android.library"
2+
apply plugin: "com.facebook.react"
23

3-
buildscript {
4-
repositories {
5-
google()
6-
mavenCentral()
4+
def DEFAULT_COMPILE_SDK_VERSION = 26
5+
def DEFAULT_BUILD_TOOLS_VERSION = "26.0.3"
6+
def DEFAULT_TARGET_SDK_VERSION = 26
7+
def DEFAULT_MIN_SDK_VERSION = 16
8+
9+
react {
10+
jsRootDir = file("..")
11+
libraryName = "RNCodePushSpec"
12+
codegenJavaPackageName = "com.microsoft.codepush.react"
13+
}
14+
15+
android {
16+
namespace "com.microsoft.codepush.react"
17+
18+
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
19+
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
20+
21+
defaultConfig {
22+
minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : DEFAULT_MIN_SDK_VERSION
23+
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
24+
versionCode 1
25+
versionName "1.0"
726
}
8-
dependencies {
9-
classpath 'com.android.tools.build:gradle:1.3.0'
1027

11-
// NOTE: Do not place your application dependencies here; they belong
12-
// in the individual module build.gradle files
28+
lintOptions {
29+
abortOnError false
1330
}
14-
}
1531

16-
allprojects {
17-
android {
18-
namespace "com.microsoft.codepush.react"
32+
defaultConfig {
33+
consumerProguardFiles 'proguard-rules.pro'
1934
}
20-
repositories {
21-
mavenLocal()
22-
mavenCentral()
35+
36+
// Builds the binary patch applier. Its sources are the shared ones at the root of the
37+
// repository, which the CMake file points at; nothing is compiled twice.
38+
externalNativeBuild {
39+
cmake {
40+
path "src/main/cpp/CMakeLists.txt"
41+
}
42+
}
43+
44+
testOptions {
45+
// The unit tests exercise plain logic, so the android framework classes they touch
46+
// in passing (logging above all) are allowed to do nothing instead of throwing.
47+
unitTests.returnDefaultValues = true
2348
}
2449
}
50+
51+
dependencies {
52+
implementation "com.facebook.react:react-native:+"
53+
54+
testImplementation "junit:junit:4.13.2"
55+
// org.json ships as stubs in the android framework jar, and the unit tests parse real
56+
// manifests, so they need an implementation that actually parses.
57+
testImplementation "org.json:json:20231013"
58+
}

‎android/gradle.properties‎

Lines changed: 0 additions & 20 deletions
This file was deleted.
-51 KB
Binary file not shown.

‎android/gradle/wrapper/gradle-wrapper.properties‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎android/gradlew‎

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)