Skip to content

Commit 4deba9c

Browse files
author
Ahmed Elshaabany
committed
Modify package.json file
1 parent 0599142 commit 4deba9c

File tree

39 files changed

+1319
-1792
lines changed

39 files changed

+1319
-1792
lines changed

template/android/app/BUCK renamed to template/android/app/_BUCK

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ android_library(
3535

3636
android_build_config(
3737
name = "build_config",
38-
package = "com.projectname",
38+
package = "com.helloworld",
3939
)
4040

4141
android_resource(
4242
name = "res",
43-
package = "com.projectname",
43+
package = "com.helloworld",
4444
res = "src/main/res",
4545
)
4646

template/android/app/build.gradle

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ import com.android.build.OutputFile
1515
* // the name of the generated asset file containing your JS bundle
1616
* bundleAssetName: "index.android.bundle",
1717
*
18-
* // the entry file for bundle generation
18+
* // the entry file for bundle generation. If none specified and
19+
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
20+
* // default. Can be overridden with ENTRY_FILE environment variable.
1921
* entryFile: "index.android.js",
2022
*
23+
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
24+
* bundleCommand: "ram-bundle",
25+
*
2126
* // whether to bundle JS and assets in debug mode
2227
* bundleInDebug: false,
2328
*
@@ -73,7 +78,7 @@ import com.android.build.OutputFile
7378
*/
7479

7580
project.ext.react = [
76-
entryFile: "index.js"
81+
enableHermes: false, // clean and rebuild if changing
7782
]
7883

7984
apply from: "../../node_modules/react-native/react.gradle"
@@ -93,6 +98,28 @@ def enableSeparateBuildPerCPUArchitecture = false
9398
*/
9499
def enableProguardInReleaseBuilds = false
95100

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

@@ -102,7 +129,7 @@ android {
102129
}
103130

104131
defaultConfig {
105-
applicationId "com.projectname"
132+
applicationId "com.helloworld"
106133
minSdkVersion rootProject.ext.minSdkVersion
107134
targetSdkVersion rootProject.ext.targetSdkVersion
108135
versionCode 1
@@ -113,34 +140,79 @@ android {
113140
reset()
114141
enable enableSeparateBuildPerCPUArchitecture
115142
universalApk false // If true, also generate a universal APK
116-
include "armeabi-v7a", "x86", "arm64-v8a", "x86-64"
143+
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
144+
}
145+
}
146+
signingConfigs {
147+
debug {
148+
storeFile file('debug.keystore')
149+
storePassword 'android'
150+
keyAlias 'androiddebugkey'
151+
keyPassword 'android'
117152
}
118153
}
119154
buildTypes {
155+
debug {
156+
signingConfig signingConfigs.debug
157+
}
120158
release {
159+
// Caution! In production, you need to generate your own keystore file.
160+
// see https://facebook.github.io/react-native/docs/signed-apk-android.
161+
signingConfig signingConfigs.debug
121162
minifyEnabled enableProguardInReleaseBuilds
122163
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
123164
}
124165
}
166+
167+
packagingOptions {
168+
pickFirst "lib/armeabi-v7a/libc++_shared.so"
169+
pickFirst "lib/arm64-v8a/libc++_shared.so"
170+
pickFirst "lib/x86/libc++_shared.so"
171+
pickFirst "lib/x86_64/libc++_shared.so"
172+
}
173+
125174
// applicationVariants are e.g. debug, release
126175
applicationVariants.all { variant ->
127176
variant.outputs.each { output ->
128177
// For each separate APK per architecture, set a unique version code as described here:
129-
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
130-
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86-64": 4]
178+
// https://developer.android.com/studio/build/configure-apk-splits.html
179+
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
131180
def abi = output.getFilter(OutputFile.ABI)
132181
if (abi != null) { // null for the universal-debug, universal-release variants
133182
output.versionCodeOverride =
134183
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
135184
}
185+
136186
}
137187
}
138188
}
139189

140190
dependencies {
141191
implementation fileTree(dir: "libs", include: ["*.jar"])
142-
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
192+
//noinspection GradleDynamicVersion
143193
implementation "com.facebook.react:react-native:+" // From node_modules
194+
195+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
196+
197+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
198+
exclude group:'com.facebook.fbjni'
199+
}
200+
201+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
202+
exclude group:'com.facebook.flipper'
203+
}
204+
205+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
206+
exclude group:'com.facebook.flipper'
207+
}
208+
209+
if (enableHermes) {
210+
def hermesPath = "../../node_modules/hermes-engine/android/";
211+
debugImplementation files(hermesPath + "hermes-debug.aar")
212+
releaseImplementation files(hermesPath + "hermes-release.aar")
213+
} else {
214+
implementation jscFlavor
215+
}
144216
}
145217

146218
// Run this once to be able to run the application with BUCK
@@ -149,3 +221,5 @@ task copyDownloadableDepsToLibs(type: Copy) {
149221
from configurations.compile
150222
into 'libs'
151223
}
224+
225+
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

template/android/app/debug.keystore

2.2 KB
Binary file not shown.

template/android/app/proguard-rules.pro

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,3 @@
88
# http://developer.android.com/guide/developing/tools/proguard.html
99

1010
# Add any project specific keep options here:
11-
12-
# If your project uses WebView with JS, uncomment the following
13-
# and specify the fully qualified class name to the JavaScript interface
14-
# class:
15-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16-
# public *;
17-
#}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools">
4-
<application tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" android:networkSecurityConfig="@xml/react_native_config" />
5-
</manifest>
4+
5+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
6+
7+
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
8+
</manifest>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
5+
* directory of this source tree.
6+
*/
7+
package com.helloworld;
8+
9+
import android.content.Context;
10+
import com.facebook.flipper.android.AndroidFlipperClient;
11+
import com.facebook.flipper.android.utils.FlipperUtils;
12+
import com.facebook.flipper.core.FlipperClient;
13+
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
14+
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
15+
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
16+
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
17+
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
18+
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
19+
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
20+
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
21+
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22+
import com.facebook.react.ReactInstanceManager;
23+
import com.facebook.react.bridge.ReactContext;
24+
import com.facebook.react.modules.network.NetworkingModule;
25+
import okhttp3.OkHttpClient;
26+
27+
public class ReactNativeFlipper {
28+
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
29+
if (FlipperUtils.shouldEnableFlipper(context)) {
30+
final FlipperClient client = AndroidFlipperClient.getInstance(context);
31+
32+
client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
33+
client.addPlugin(new ReactFlipperPlugin());
34+
client.addPlugin(new DatabasesFlipperPlugin(context));
35+
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
36+
client.addPlugin(CrashReporterPlugin.getInstance());
37+
38+
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
39+
NetworkingModule.setCustomClientBuilder(
40+
new NetworkingModule.CustomClientBuilder() {
41+
@Override
42+
public void apply(OkHttpClient.Builder builder) {
43+
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
44+
}
45+
});
46+
client.addPlugin(networkFlipperPlugin);
47+
client.start();
48+
49+
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
50+
// Hence we run if after all native modules have been initialized
51+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
52+
if (reactContext == null) {
53+
reactInstanceManager.addReactInstanceEventListener(
54+
new ReactInstanceManager.ReactInstanceEventListener() {
55+
@Override
56+
public void onReactContextInitialized(ReactContext reactContext) {
57+
reactInstanceManager.removeReactInstanceEventListener(this);
58+
reactContext.runOnNativeModulesQueueThread(
59+
new Runnable() {
60+
@Override
61+
public void run() {
62+
client.addPlugin(new FrescoFlipperPlugin());
63+
}
64+
});
65+
}
66+
});
67+
} else {
68+
client.addPlugin(new FrescoFlipperPlugin());
69+
}
70+
}
71+
}
72+
}

template/android/app/src/debug/res/xml/react_native_config.xml

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

template/android/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.projectname">
2+
package="com.helloworld">
33

44
<uses-permission android:name="android.permission.INTERNET" />
5-
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
65

76
<application
87
android:name=".MainApplication"
@@ -14,7 +13,8 @@
1413
<activity
1514
android:name=".MainActivity"
1615
android:label="@string/app_name"
17-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
16+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
17+
android:launchMode="singleTask"
1818
android:windowSoftInputMode="adjustResize">
1919
<intent-filter>
2020
<action android:name="android.intent.action.MAIN" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.helloworld;
2+
3+
import com.facebook.react.ReactActivity;
4+
5+
public class MainActivity extends ReactActivity {
6+
7+
/**
8+
* Returns the name of the main component registered from JavaScript. This is used to schedule
9+
* rendering of the component.
10+
*/
11+
@Override
12+
protected String getMainComponentName() {
13+
return "HelloWorld";
14+
}
15+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.helloworld;
2+
3+
import android.app.Application;
4+
import android.content.Context;
5+
import com.facebook.react.PackageList;
6+
import com.facebook.react.ReactApplication;
7+
import com.facebook.react.ReactInstanceManager;
8+
import com.facebook.react.ReactNativeHost;
9+
import com.facebook.react.ReactPackage;
10+
import com.facebook.soloader.SoLoader;
11+
import java.lang.reflect.InvocationTargetException;
12+
import java.util.List;
13+
14+
public class MainApplication extends Application implements ReactApplication {
15+
16+
private final ReactNativeHost mReactNativeHost =
17+
new ReactNativeHost(this) {
18+
@Override
19+
public boolean getUseDeveloperSupport() {
20+
return BuildConfig.DEBUG;
21+
}
22+
23+
@Override
24+
protected List<ReactPackage> getPackages() {
25+
@SuppressWarnings("UnnecessaryLocalVariable")
26+
List<ReactPackage> packages = new PackageList(this).getPackages();
27+
// Packages that cannot be autolinked yet can be added manually here, for example:
28+
// packages.add(new MyReactNativePackage());
29+
return packages;
30+
}
31+
32+
@Override
33+
protected String getJSMainModuleName() {
34+
return "index";
35+
}
36+
};
37+
38+
@Override
39+
public ReactNativeHost getReactNativeHost() {
40+
return mReactNativeHost;
41+
}
42+
43+
@Override
44+
public void onCreate() {
45+
super.onCreate();
46+
SoLoader.init(this, /* native exopackage */ false);
47+
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
48+
}
49+
50+
/**
51+
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
52+
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
53+
*
54+
* @param context
55+
* @param reactInstanceManager
56+
*/
57+
private static void initializeFlipper(
58+
Context context, ReactInstanceManager reactInstanceManager) {
59+
if (BuildConfig.DEBUG) {
60+
try {
61+
/*
62+
We use reflection here to pick up the class that initializes Flipper,
63+
since Flipper library is not available in release mode
64+
*/
65+
Class<?> aClass = Class.forName("com.helloworld.ReactNativeFlipper");
66+
aClass
67+
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
68+
.invoke(null, context, reactInstanceManager);
69+
} catch (ClassNotFoundException e) {
70+
e.printStackTrace();
71+
} catch (NoSuchMethodException e) {
72+
e.printStackTrace();
73+
} catch (IllegalAccessException e) {
74+
e.printStackTrace();
75+
} catch (InvocationTargetException e) {
76+
e.printStackTrace();
77+
}
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)