Description
Environment
System:
OS: macOS 10.15.5
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Memory: 1.17 GB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 6.7.0 - ~/.nvm/versions/node/v10.13.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 23, 28, 29
Build Tools: 28.0.3, 29.0.2, 29.0.3
System Images: android-29 | Google Play Intel x86 Atom
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
react: 16.13.1 => 16.13.1
react-native: 0.63.1 => 0.63.1
Upgrading version
0.59.10 ->0.63.1
Description
Our application is a hybrid and it consume our react native in android as a library. After following the upgrade guide and upgrading all our packages to the latest, I'm running into an issue where some gradle task called packageDebug
is null
running ./gradle clean build --stacktrace
from the android repo results in the output below
FAILURE: Build failed with an exception.
* Where:
Script '/Users/mberber/metromile/growth-prototypes/node_modules/react-native/react.gradle' line: 348
* What went wrong:
A problem occurred configuring project ':lib-reactnative'.
> Cannot invoke method doFirst() on null object
if I edit the react native gradle file on line 346 to disable vm cleanup:
if (!enableVmCleanup) {
def task = tasks.findByName("package${targetName}")
task.doFirst(vmSelectionAction)
}
and run the build again, react native cannot find the correct paths to any jars to jetify:
> Could not resolve all artifacts for configuration ':lib-reactnative:releaseCompileClasspath'.
> Failed to transform react-native-reanimated.aar (project :react-native-reanimated) to match attributes {artifactType=jar}.
> Failed to transform react-native-gesture-handler.aar (project :react-native-gesture-handler) to match attributes {artifactType=jar}.
> Execution failed for JetifyTransform: /Users/mberber/metromile/growth-prototypes/node_modules/react-native-gesture-handler/android/build/outputs/aar/react-native-gesture-handler-release.aar.
...etc...
./android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.5.3")
classpath("com.kezong:fat-aar:1.2.8")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id("nu.studer.credentials") version "1.0.7"
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven { url "https://www.jitpack.io" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from yarn
url("$rootDir/../node_modules/react-native/android")
}
maven {
// expo-camera bundles a custom com.google.android:cameraview
url("$rootDir/../node_modules/expo-camera/android/maven")
}
maven {
// Android JSC is installed from yarn
url("$rootDir/../node_modules/jsc-android/dist")
}
}
}
wrapper {
gradleVersion = '4.7'
distributionUrl = distributionUrl.replace("bin", "all")
}
./android/app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]
/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion 29
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.metromile.mobile.reactnative"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation project(':lib-reactnative')
// Import all react native dependencies
parent.allprojects
.findAll { it.name.startsWith('unimodules-') or it.name.startsWith('expo-') or it.name.startsWith('react-native-') }
.each {
dependencies.add("implementation", project(":${it.name}"))
}
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
./android/lib-reactnative/build.gradle
apply plugin: "com.android.library"
apply plugin: "com.kezong.fat-aar"
apply plugin: "maven-publish"
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
entryFile: "index.js",
inputExcludes: ["android/**", "ios/**", "simple-native-ios/**"],
bundleInRelease: false
]
apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
repositories {
flatDir {
dirs 'libs'
}
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
multiDexEnabled true
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.8"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
buildTypes {
debug {
manifestPlaceholders = [usesCleartextTraffic:"true"] // https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted
}
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
manifestPlaceholders = [usesCleartextTraffic:"false"]
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// publishing details are omitted
// Testing libraries
useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'
}
dependencies {
embed project(path: ':react-native-reanimated', configuration: 'default')
embed project(path: ':react-native-gesture-handler', configuration: 'default')
embed project(path: ':react-native-svg', configuration: 'default')
embed project(path: ':react-native-webview', configuration: 'default')
embed ('com.google.android:cameraview:1.0.0') {
exclude group: 'com.android.support'
}
implementation 'com.android.support:support-annotations:+'
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
implementation('com.google.android.gms:play-services-vision:16.2.0') {
exclude group: 'com.android.support'
}
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.12.1'
implementation fileTree(dir: "libs", include: ["*.jar"])
compileOnly 'androidx.appcompat:appcompat:1.0.0'
// compileOnly "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
addUnimodulesDependencies([ configuration: 'embed' ])
// Unimodules need to define the targetConfiguration as `default` when used as `embed`
project.configurations
.collectMany { it.allDependencies }
.findAll { it.name.startsWith('unimodules-') or it.name.startsWith('expo-') }
.each {
it.targetConfiguration = 'default'
}
testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'org.mockito:mockito-core:2.28.2'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
testImplementation 'org.json:json:20080701'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
// Disable Assests building, as we don't bundle them directly in a our builds
tasks.whenTaskAdded { Task task ->
if(task.name.contains("JsAndAssets")) {
println "Disabling ${task}"
task.enabled = false
}
}
// Assure things are built before publishing
tasks.withType(AbstractPublishToMaven) { it.dependsOn build }