Skip to content

Commit b46b068

Browse files
author
Kai Guo
committed
Fix Android build
1 parent 4b44bac commit b46b068

File tree

8 files changed

+88
-11
lines changed

8 files changed

+88
-11
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ jobs:
186186
# Build and test
187187
- run:
188188
name: Build Android apk
189-
command: cd example/android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release --max-workers 2
189+
command: cd example/android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release --max-workers 2 -x bundleReleaseJsAndAssets
190190

191191
- persist_to_workspace:
192192
root: ~/async_storage

.circleci/scripts/run_android_e2e.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ MAX_RETRIES=60 # wait max 5 minutes for emu to boot
1111
build_apk() {
1212
echo
1313
echo "[Detox e2e] Building APK"
14+
eval "mkdir example/android/app/src/main/assets"
15+
eval "react-native bundle --platform android --dev false --entry-file example/index.js --bundle-output example/android/app/src/main/assets/index.bundle --assets-dest example/android/app/src/main/res/"
1416
cd "example/android"
15-
eval "./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release"
17+
eval "./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release -x bundleReleaseJsAndAssets"
1618
cd ${ROOT_DIR}
1719
}
1820

example/android/app/build.gradle

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ import com.android.build.OutputFile
7676
project.ext.react = [
7777
cliPath: "./node_modules/react-native/local-cli/cli.js",
7878
entryFile: "./example/index.js",
79-
root: "../../../"
79+
root: "../../../",
80+
enableHermes: false,
8081
]
8182

8283

@@ -98,6 +99,28 @@ def enableSeparateBuildPerCPUArchitecture = false
9899
*/
99100
def enableProguardInReleaseBuilds = false
100101

102+
/**
103+
* The preferred build flavor of JavaScriptCore.
104+
*
105+
* For example, to use the international variant, you can use:
106+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
107+
*
108+
* The international variant includes ICU i18n library and necessary data
109+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
110+
* give correct results when using with locales other than en-US. Note that
111+
* this variant is about 6MiB larger per architecture than default.
112+
*/
113+
def jscFlavor = 'org.webkit:android-jsc:+'
114+
115+
/**
116+
* Whether to enable the Hermes VM.
117+
*
118+
* This should be set on project.ext.react and mirrored here. If it is not set
119+
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
120+
* and the benefits of using Hermes will therefore be sharply reduced.
121+
*/
122+
def enableHermes = project.ext.react.get("enableHermes", false);
123+
101124
android {
102125
compileSdkVersion rootProject.ext.compileSdkVersion
103126

@@ -163,6 +186,15 @@ dependencies {
163186
// tests
164187
androidTestImplementation ('com.wix:detox:+') { transitive = true }
165188
androidTestImplementation 'junit:junit:4.12'
189+
190+
191+
if (enableHermes) {
192+
def hermesPath = "../../../node_modules/hermes-engine/android/";
193+
debugImplementation files(hermesPath + "hermes-debug.aar")
194+
releaseImplementation files(hermesPath + "hermes-release.aar")
195+
} else {
196+
implementation jscFlavor
197+
}
166198
}
167199

168200
// Run this once to be able to run the application with BUCK
@@ -171,3 +203,5 @@ task copyDownloadableDepsToLibs(type: Copy) {
171203
from configurations.compile
172204
into 'libs'
173205
}
206+
207+
apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

example/android/app/src/main/java/com/asyncstorageexample/MainApplication.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package com.asyncstorageexample;
22

33
import android.app.Application;
4-
4+
import android.content.Context;
5+
import com.facebook.react.PackageList;
56
import com.facebook.react.ReactApplication;
67
import com.facebook.react.ReactNativeHost;
78
import com.facebook.react.ReactPackage;
89
import com.facebook.react.shell.MainReactPackage;
910
import com.facebook.soloader.SoLoader;
1011
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
1112

13+
import java.lang.reflect.InvocationTargetException;
1214
import java.util.Arrays;
1315
import java.util.List;
1416

@@ -22,10 +24,10 @@ public boolean getUseDeveloperSupport() {
2224

2325
@Override
2426
protected List<ReactPackage> getPackages() {
25-
return Arrays.<ReactPackage>asList(
26-
new MainReactPackage(),
27-
new AsyncStoragePackage()
28-
);
27+
@SuppressWarnings("UnnecessaryLocalVariable")
28+
List<ReactPackage> packages = new PackageList(this).getPackages();
29+
packages.add(new AsyncStoragePackage());
30+
return packages;
2931
}
3032

3133
@Override

example/android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ allprojects {
2929
url "$rootDir/../../node_modules/react-native/android"
3030
}
3131
maven { url "$rootDir/../../node_modules/detox/Detox-android" }
32+
maven { url "https://jitpack.io" }
33+
maven { url "$rootDir/../../node_modules/jsc-android/dist" }
3234
}
3335
}

example/android/settings.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
rootProject.name = 'AsyncStorageExample'
22

3+
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
4+
35
include ':app'
46
include ':rnAsyncStorage'
57

6-
78
project(':rnAsyncStorage').projectDir = new File(rootProject.projectDir, '../../android')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@babel/runtime": "^7.6.2",
5050
"@react-native-community/eslint-config": "^0.0.5",
5151
"@react-native-community/cli-platform-ios": "3.0.0",
52+
"@react-native-community/cli-platform-android": "4.6.3",
5253
"babel-jest": "^24.9.0",
5354
"babel-plugin-module-resolver": "3.1.3",
5455
"detox": "12.6.1",

yarn.lock

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,22 @@
12911291
dependencies:
12921292
serve-static "^1.13.1"
12931293

1294+
"@react-native-community/cli-platform-android@4.6.3":
1295+
version "4.6.3"
1296+
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-android/-/cli-platform-android-4.6.3.tgz#a7377b97cb85b5714d063281eed8e4185444569d"
1297+
integrity sha512-o88nUW2mjwvYSTwW/VTPdMmTi2vHS4T4gYGObb3qgkv/6H0JG1NC0SRo1FCHRpRGo1nQ7d+aB8sfpJeEkQ3Mbw==
1298+
dependencies:
1299+
"@react-native-community/cli-tools" "^4.6.3"
1300+
chalk "^3.0.0"
1301+
execa "^1.0.0"
1302+
fs-extra "^8.1.0"
1303+
glob "^7.1.3"
1304+
jetifier "^1.6.2"
1305+
lodash "^4.17.15"
1306+
logkitty "^0.6.0"
1307+
slash "^3.0.0"
1308+
xmldoc "^1.1.2"
1309+
12941310
"@react-native-community/cli-platform-android@^2.6.0", "@react-native-community/cli-platform-android@^2.9.0":
12951311
version "2.9.0"
12961312
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-android/-/cli-platform-android-2.9.0.tgz#28831e61ce565a2c7d1905852fce1eecfd33cb5e"
@@ -1366,6 +1382,16 @@
13661382
mime "^2.4.1"
13671383
node-fetch "^2.5.0"
13681384

1385+
"@react-native-community/cli-tools@^4.6.3":
1386+
version "4.6.3"
1387+
resolved "https://registry.yarnpkg.com/@react-native-community/cli-tools/-/cli-tools-4.6.3.tgz#dab9ce5fc45ae8847caa9f6cc85b67b284777b1f"
1388+
integrity sha512-ne/A1JUA86WgS3LpdqCwdpCbzfLJusfTllv+TDafNxEdziGPwTcRmeOk3QD3X0rwSawCJhfcnROzIc4AnfSP3w==
1389+
dependencies:
1390+
chalk "^3.0.0"
1391+
lodash "^4.17.15"
1392+
mime "^2.4.1"
1393+
node-fetch "^2.6.0"
1394+
13691395
"@react-native-community/cli-types@^3.0.0":
13701396
version "3.0.0"
13711397
resolved "https://registry.yarnpkg.com/@react-native-community/cli-types/-/cli-types-3.0.0.tgz#488d46605cb05e88537e030f38da236eeda74652"
@@ -3741,6 +3767,15 @@ fs-extra@^7.0.1:
37413767
jsonfile "^4.0.0"
37423768
universalify "^0.1.0"
37433769

3770+
fs-extra@^8.1.0:
3771+
version "8.1.0"
3772+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
3773+
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
3774+
dependencies:
3775+
graceful-fs "^4.2.0"
3776+
jsonfile "^4.0.0"
3777+
universalify "^0.1.0"
3778+
37443779
fs.realpath@^1.0.0:
37453780
version "1.0.0"
37463781
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -3851,7 +3886,7 @@ globals@^11.7.0:
38513886
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
38523887
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
38533888

3854-
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
3889+
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0:
38553890
version "4.2.3"
38563891
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.3.tgz#4a12ff1b60376ef09862c2093edd908328be8423"
38573892
integrity sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==
@@ -5780,7 +5815,7 @@ node-fetch@^1.0.1:
57805815
encoding "^0.1.11"
57815816
is-stream "^1.0.1"
57825817

5783-
node-fetch@^2.2.0, node-fetch@^2.5.0:
5818+
node-fetch@^2.2.0, node-fetch@^2.5.0, node-fetch@^2.6.0:
57845819
version "2.6.0"
57855820
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
57865821
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==

0 commit comments

Comments
 (0)