Skip to content

Commit 50790e5

Browse files
committed
add react native app structure example
1 parent 6dffbbe commit 50790e5

File tree

1,913 files changed

+60213
-0
lines changed

Some content is hidden

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

1,913 files changed

+60213
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'react-native';
2+
import React from 'react';
3+
import Index from '../index.android.js';
4+
5+
// Note: test renderer must be required after react-native.
6+
import renderer from 'react-test-renderer';
7+
8+
it('renders correctly', () => {
9+
const tree = renderer.create(
10+
<Index />
11+
);
12+
});
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'react-native';
2+
import React from 'react';
3+
import Index from '../index.ios.js';
4+
5+
// Note: test renderer must be required after react-native.
6+
import renderer from 'react-test-renderer';
7+
8+
it('renders correctly', () => {
9+
const tree = renderer.create(
10+
<Index />
11+
);
12+
});

react-native/fuc/android/app/BUCK

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# To learn about Buck see [Docs](https://buckbuild.com/).
2+
# To run your application with Buck:
3+
# - install Buck
4+
# - `npm start` - to start the packager
5+
# - `cd android`
6+
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7+
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8+
# - `buck install -r android/app` - compile, install and run application
9+
#
10+
11+
lib_deps = []
12+
13+
for jarfile in glob(['libs/*.jar']):
14+
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
15+
lib_deps.append(':' + name)
16+
prebuilt_jar(
17+
name = name,
18+
binary_jar = jarfile,
19+
)
20+
21+
for aarfile in glob(['libs/*.aar']):
22+
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
23+
lib_deps.append(':' + name)
24+
android_prebuilt_aar(
25+
name = name,
26+
aar = aarfile,
27+
)
28+
29+
android_library(
30+
name = "all-libs",
31+
exported_deps = lib_deps,
32+
)
33+
34+
android_library(
35+
name = "app-code",
36+
srcs = glob([
37+
"src/main/java/**/*.java",
38+
]),
39+
deps = [
40+
":all-libs",
41+
":build_config",
42+
":res",
43+
],
44+
)
45+
46+
android_build_config(
47+
name = "build_config",
48+
package = "com.fuc",
49+
)
50+
51+
android_resource(
52+
name = "res",
53+
package = "com.fuc",
54+
res = "src/main/res",
55+
)
56+
57+
android_binary(
58+
name = "app",
59+
keystore = "//android/keystores:debug",
60+
manifest = "src/main/AndroidManifest.xml",
61+
package_type = "debug",
62+
deps = [
63+
":app-code",
64+
],
65+
)
+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
apply plugin: "com.android.application"
2+
3+
import com.android.build.OutputFile
4+
5+
/**
6+
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7+
* and bundleReleaseJsAndAssets).
8+
* These basically call `react-native bundle` with the correct arguments during the Android build
9+
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10+
* bundle directly from the development server. Below you can see all the possible configurations
11+
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12+
* `apply from: "../../node_modules/react-native/react.gradle"` line.
13+
*
14+
* project.ext.react = [
15+
* // the name of the generated asset file containing your JS bundle
16+
* bundleAssetName: "index.android.bundle",
17+
*
18+
* // the entry file for bundle generation
19+
* entryFile: "index.android.js",
20+
*
21+
* // whether to bundle JS and assets in debug mode
22+
* bundleInDebug: false,
23+
*
24+
* // whether to bundle JS and assets in release mode
25+
* bundleInRelease: true,
26+
*
27+
* // whether to bundle JS and assets in another build variant (if configured).
28+
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29+
* // The configuration property can be in the following formats
30+
* // 'bundleIn${productFlavor}${buildType}'
31+
* // 'bundleIn${buildType}'
32+
* // bundleInFreeDebug: true,
33+
* // bundleInPaidRelease: true,
34+
* // bundleInBeta: true,
35+
*
36+
* // whether to disable dev mode in custom build variants (by default only disabled in release)
37+
* // for example: to disable dev mode in the staging build type (if configured)
38+
* devDisabledInStaging: true,
39+
* // The configuration property can be in the following formats
40+
* // 'devDisabledIn${productFlavor}${buildType}'
41+
* // 'devDisabledIn${buildType}'
42+
*
43+
* // the root of your project, i.e. where "package.json" lives
44+
* root: "../../",
45+
*
46+
* // where to put the JS bundle asset in debug mode
47+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
48+
*
49+
* // where to put the JS bundle asset in release mode
50+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
51+
*
52+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
53+
* // require('./image.png')), in debug mode
54+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
55+
*
56+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
57+
* // require('./image.png')), in release mode
58+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
59+
*
60+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
61+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
62+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
63+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
64+
* // for example, you might want to remove it from here.
65+
* inputExcludes: ["android/**", "ios/**"],
66+
*
67+
* // override which node gets called and with what additional arguments
68+
* nodeExecutableAndArgs: ["node"],
69+
*
70+
* // supply additional arguments to the packager
71+
* extraPackagerArgs: []
72+
* ]
73+
*/
74+
75+
apply from: "../../node_modules/react-native/react.gradle"
76+
77+
/**
78+
* Set this to true to create two separate APKs instead of one:
79+
* - An APK that only works on ARM devices
80+
* - An APK that only works on x86 devices
81+
* The advantage is the size of the APK is reduced by about 4MB.
82+
* Upload all the APKs to the Play Store and people will download
83+
* the correct one based on the CPU architecture of their device.
84+
*/
85+
def enableSeparateBuildPerCPUArchitecture = false
86+
87+
/**
88+
* Run Proguard to shrink the Java bytecode in release builds.
89+
*/
90+
def enableProguardInReleaseBuilds = false
91+
92+
android {
93+
compileSdkVersion 23
94+
buildToolsVersion "23.0.1"
95+
96+
defaultConfig {
97+
applicationId "com.fuc"
98+
minSdkVersion 16
99+
targetSdkVersion 22
100+
versionCode 1
101+
versionName "1.0"
102+
ndk {
103+
abiFilters "armeabi-v7a", "x86"
104+
}
105+
}
106+
splits {
107+
abi {
108+
reset()
109+
enable enableSeparateBuildPerCPUArchitecture
110+
universalApk false // If true, also generate a universal APK
111+
include "armeabi-v7a", "x86"
112+
}
113+
}
114+
buildTypes {
115+
release {
116+
minifyEnabled enableProguardInReleaseBuilds
117+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
118+
}
119+
}
120+
// applicationVariants are e.g. debug, release
121+
applicationVariants.all { variant ->
122+
variant.outputs.each { output ->
123+
// For each separate APK per architecture, set a unique version code as described here:
124+
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
125+
def versionCodes = ["armeabi-v7a":1, "x86":2]
126+
def abi = output.getFilter(OutputFile.ABI)
127+
if (abi != null) { // null for the universal-debug, universal-release variants
128+
output.versionCodeOverride =
129+
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
130+
}
131+
}
132+
}
133+
}
134+
135+
dependencies {
136+
compile fileTree(dir: "libs", include: ["*.jar"])
137+
compile "com.android.support:appcompat-v7:23.0.1"
138+
compile "com.facebook.react:react-native:+" // From node_modules
139+
}
140+
141+
// Run this once to be able to run the application with BUCK
142+
// puts all compile dependencies into folder libs for BUCK to use
143+
task copyDownloadableDepsToLibs(type: Copy) {
144+
from configurations.compile
145+
into 'libs'
146+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
30+
31+
# Do not strip any method/class that is annotated with @DoNotStrip
32+
-keep @com.facebook.proguard.annotations.DoNotStrip class *
33+
-keep @com.facebook.common.internal.DoNotStrip class *
34+
-keepclassmembers class * {
35+
@com.facebook.proguard.annotations.DoNotStrip *;
36+
@com.facebook.common.internal.DoNotStrip *;
37+
}
38+
39+
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
40+
void set*(***);
41+
*** get*();
42+
}
43+
44+
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
45+
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
46+
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
47+
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
48+
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
49+
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
50+
51+
-dontwarn com.facebook.react.**
52+
53+
# TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
54+
# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
55+
-dontwarn android.text.StaticLayout
56+
57+
# okhttp
58+
59+
-keepattributes Signature
60+
-keepattributes *Annotation*
61+
-keep class okhttp3.** { *; }
62+
-keep interface okhttp3.** { *; }
63+
-dontwarn okhttp3.**
64+
65+
# okio
66+
67+
-keep class sun.misc.Unsafe { *; }
68+
-dontwarn java.nio.file.*
69+
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
70+
-dontwarn okio.**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.fuc"
3+
android:versionCode="1"
4+
android:versionName="1.0">
5+
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
8+
9+
<uses-sdk
10+
android:minSdkVersion="16"
11+
android:targetSdkVersion="22" />
12+
13+
<application
14+
android:name=".MainApplication"
15+
android:allowBackup="true"
16+
android:label="@string/app_name"
17+
android:icon="@mipmap/ic_launcher"
18+
android:theme="@style/AppTheme">
19+
<activity
20+
android:name=".MainActivity"
21+
android:label="@string/app_name"
22+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
23+
android:windowSoftInputMode="adjustResize">
24+
<intent-filter>
25+
<action android:name="android.intent.action.MAIN" />
26+
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
</activity>
29+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
30+
</application>
31+
32+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.fuc;
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.
9+
* This is used to schedule rendering of the component.
10+
*/
11+
@Override
12+
protected String getMainComponentName() {
13+
return "fuc";
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fuc;
2+
3+
import android.app.Application;
4+
5+
import com.facebook.react.ReactApplication;
6+
import com.facebook.react.ReactNativeHost;
7+
import com.facebook.react.ReactPackage;
8+
import com.facebook.react.shell.MainReactPackage;
9+
import com.facebook.soloader.SoLoader;
10+
11+
import java.util.Arrays;
12+
import java.util.List;
13+
14+
public class MainApplication extends Application implements ReactApplication {
15+
16+
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
17+
@Override
18+
public boolean getUseDeveloperSupport() {
19+
return BuildConfig.DEBUG;
20+
}
21+
22+
@Override
23+
protected List<ReactPackage> getPackages() {
24+
return Arrays.<ReactPackage>asList(
25+
new MainReactPackage()
26+
);
27+
}
28+
};
29+
30+
@Override
31+
public ReactNativeHost getReactNativeHost() {
32+
return mReactNativeHost;
33+
}
34+
35+
@Override
36+
public void onCreate() {
37+
super.onCreate();
38+
SoLoader.init(this, /* native exopackage */ false);
39+
}
40+
}
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)