Skip to content

Commit e62e46f

Browse files
committed
update react-native from 0.7.1 to 0.17.0
新建工程并按照新的React Native目录结构调整文件位置
1 parent adf46e9 commit e62e46f

File tree

49 files changed

+778
-99
lines changed

Some content is hidden

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

49 files changed

+778
-99
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
apply plugin: "com.android.application"
2+
3+
/**
4+
* The react.gradle file registers two tasks: bundleDebugJsAndAssets and bundleReleaseJsAndAssets.
5+
* These basically call `react-native bundle` with the correct arguments during the Android build
6+
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
7+
* bundle directly from the development server. Below you can see all the possible configurations
8+
* and their defaults. If you decide to add a configuration block, make sure to add it before the
9+
* `apply from: "react.gradle"` line.
10+
*
11+
* project.ext.react = [
12+
* // the name of the generated asset file containing your JS bundle
13+
* bundleAssetName: "index.android.bundle",
14+
*
15+
* // the entry file for bundle generation
16+
* entryFile: "index.android.js",
17+
*
18+
* // whether to bundle JS and assets in debug mode
19+
* bundleInDebug: false,
20+
*
21+
* // whether to bundle JS and assets in release mode
22+
* bundleInRelease: true,
23+
*
24+
* // the root of your project, i.e. where "package.json" lives
25+
* root: "../../",
26+
*
27+
* // where to put the JS bundle asset in debug mode
28+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
29+
*
30+
* // where to put the JS bundle asset in release mode
31+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
32+
*
33+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
34+
* // require('./image.png')), in debug mode
35+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
36+
*
37+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
38+
* // require('./image.png')), in release mode
39+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
40+
*
41+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
42+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
43+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
44+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
45+
* // for example, you might want to remove it from here.
46+
* inputExcludes: ["android/**", "ios/**"]
47+
* ]
48+
*/
49+
50+
apply from: "react.gradle"
51+
52+
android {
53+
compileSdkVersion 23
54+
buildToolsVersion "23.0.1"
55+
56+
defaultConfig {
57+
applicationId "com.address_book"
58+
minSdkVersion 16
59+
targetSdkVersion 22
60+
versionCode 1
61+
versionName "1.0"
62+
ndk {
63+
abiFilters "armeabi-v7a", "x86"
64+
}
65+
}
66+
buildTypes {
67+
release {
68+
minifyEnabled false // Set this to true to enable Proguard
69+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
70+
}
71+
}
72+
}
73+
74+
dependencies {
75+
compile fileTree(dir: "libs", include: ["*.jar"])
76+
compile "com.android.support:appcompat-v7:23.0.1"
77+
compile "com.facebook.react:react-native:0.17.+"
78+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# 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+
#}
18+
19+
# Disabling obfuscation is useful if you collect stack traces from production crashes
20+
# (unless you are using a system that supports de-obfuscate the stack traces).
21+
-dontobfuscate
22+
23+
# React Native
24+
25+
# Keep our interfaces so they can be used by other ProGuard rules.
26+
# See http://sourceforge.net/p/proguard/bugs/466/
27+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29+
30+
# Do not strip any method/class that is annotated with @DoNotStrip
31+
-keep @com.facebook.proguard.annotations.DoNotStrip class *
32+
-keepclassmembers class * {
33+
@com.facebook.proguard.annotations.DoNotStrip *;
34+
}
35+
36+
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
37+
void set*(***);
38+
*** get*();
39+
}
40+
41+
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
42+
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
43+
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
44+
-keepclassmembers class * { @com.facebook.react.uimanager.ReactProp <methods>; }
45+
-keepclassmembers class * { @com.facebook.react.uimanager.ReactPropGroup <methods>; }
46+
47+
# okhttp
48+
49+
-keepattributes Signature
50+
-keepattributes *Annotation*
51+
-keep class com.squareup.okhttp.** { *; }
52+
-keep interface com.squareup.okhttp.** { *; }
53+
-dontwarn com.squareup.okhttp.**
54+
55+
# okio
56+
57+
-keep class sun.misc.Unsafe { *; }
58+
-dontwarn java.nio.file.*
59+
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
60+
-dontwarn okio.**
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import org.apache.tools.ant.taskdefs.condition.Os
2+
3+
def config = project.hasProperty("react") ? project.react : [];
4+
5+
def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
6+
def entryFile = config.entryFile ?: "index.android.js"
7+
8+
// because elvis operator
9+
def elvisFile(thing) {
10+
return thing ? file(thing) : null;
11+
}
12+
13+
def reactRoot = elvisFile(config.root) ?: file("../../")
14+
def jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?:
15+
file("$buildDir/intermediates/assets/debug")
16+
def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?:
17+
file("$buildDir/intermediates/assets/release")
18+
def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?:
19+
file("$buildDir/intermediates/res/merged/debug")
20+
def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?:
21+
file("$buildDir/intermediates/res/merged/release")
22+
def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
23+
24+
def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName")
25+
def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName")
26+
27+
task bundleDebugJsAndAssets(type: Exec) {
28+
// create dirs if they are not there (e.g. the "clean" task just ran)
29+
doFirst {
30+
jsBundleDirDebug.mkdirs()
31+
resourcesDirDebug.mkdirs()
32+
}
33+
34+
// set up inputs and outputs so gradle can cache the result
35+
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
36+
outputs.dir jsBundleDirDebug
37+
outputs.dir resourcesDirDebug
38+
39+
// set up the call to the react-native cli
40+
workingDir reactRoot
41+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
42+
commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
43+
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
44+
} else {
45+
commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
46+
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
47+
}
48+
49+
enabled config.bundleInDebug ?: false
50+
}
51+
52+
task bundleReleaseJsAndAssets(type: Exec) {
53+
// create dirs if they are not there (e.g. the "clean" task just ran)
54+
doFirst {
55+
jsBundleDirRelease.mkdirs()
56+
resourcesDirRelease.mkdirs()
57+
}
58+
59+
// set up inputs and outputs so gradle can cache the result
60+
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
61+
outputs.dir jsBundleDirRelease
62+
outputs.dir resourcesDirRelease
63+
64+
// set up the call to the react-native cli
65+
workingDir reactRoot
66+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
67+
commandLine "cmd","/c", "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
68+
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
69+
} else {
70+
commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
71+
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
72+
}
73+
74+
enabled config.bundleInRelease ?: true
75+
}
76+
77+
gradle.projectsEvaluated {
78+
// hook bundleDebugJsAndAssets into the android build process
79+
bundleDebugJsAndAssets.dependsOn mergeDebugResources
80+
bundleDebugJsAndAssets.dependsOn mergeDebugAssets
81+
processDebugResources.dependsOn bundleDebugJsAndAssets
82+
83+
// hook bundleReleaseJsAndAssets into the android build process
84+
bundleReleaseJsAndAssets.dependsOn mergeReleaseResources
85+
bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets
86+
processReleaseResources.dependsOn bundleReleaseJsAndAssets
87+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.address_book">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application
7+
android:allowBackup="true"
8+
android:label="@string/app_name"
9+
android:icon="@mipmap/ic_launcher"
10+
android:theme="@style/AppTheme">
11+
<activity
12+
android:name=".MainActivity"
13+
android:label="@string/app_name"
14+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
21+
</application>
22+
23+
</manifest>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.address_book;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.view.KeyEvent;
6+
7+
import com.facebook.react.LifecycleState;
8+
import com.facebook.react.ReactInstanceManager;
9+
import com.facebook.react.ReactRootView;
10+
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
11+
import com.facebook.react.shell.MainReactPackage;
12+
import com.facebook.soloader.SoLoader;
13+
14+
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
15+
16+
private ReactInstanceManager mReactInstanceManager;
17+
private ReactRootView mReactRootView;
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
mReactRootView = new ReactRootView(this);
23+
24+
mReactInstanceManager = ReactInstanceManager.builder()
25+
.setApplication(getApplication())
26+
.setBundleAssetName("index.android.bundle")
27+
.setJSMainModuleName("index.android")
28+
.addPackage(new MainReactPackage())
29+
.setUseDeveloperSupport(BuildConfig.DEBUG)
30+
.setInitialLifecycleState(LifecycleState.RESUMED)
31+
.build();
32+
33+
mReactRootView.startReactApplication(mReactInstanceManager, "address_book", null);
34+
35+
setContentView(mReactRootView);
36+
}
37+
38+
@Override
39+
public boolean onKeyUp(int keyCode, KeyEvent event) {
40+
if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {
41+
mReactInstanceManager.showDevOptionsDialog();
42+
return true;
43+
}
44+
return super.onKeyUp(keyCode, event);
45+
}
46+
47+
@Override
48+
public void onBackPressed() {
49+
if (mReactInstanceManager != null) {
50+
mReactInstanceManager.onBackPressed();
51+
} else {
52+
super.onBackPressed();
53+
}
54+
}
55+
56+
@Override
57+
public void invokeDefaultOnBackPressed() {
58+
super.onBackPressed();
59+
}
60+
61+
@Override
62+
protected void onPause() {
63+
super.onPause();
64+
65+
if (mReactInstanceManager != null) {
66+
mReactInstanceManager.onPause();
67+
}
68+
}
69+
70+
@Override
71+
protected void onResume() {
72+
super.onResume();
73+
74+
if (mReactInstanceManager != null) {
75+
mReactInstanceManager.onResume(this, this);
76+
}
77+
}
78+
}
3.34 KB
Loading
2.15 KB
Loading
4.73 KB
Loading
7.54 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">address_book</string>
3+
</resources>

0 commit comments

Comments
 (0)