Skip to content

Commit da5072b

Browse files
committed
chore: native builds
1 parent ed73eca commit da5072b

File tree

74 files changed

+3517
-13
lines changed

Some content is hidden

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

74 files changed

+3517
-13
lines changed

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,9 @@ module.exports = {
8686

8787
## Running
8888

89-
### Prequisites
89+
### Prerequisites
9090

91-
#### iOS
92-
93-
1. Install XCode
94-
2. Install iOS (XCode > Settings > Platforms > Install the latest iOS version)
95-
96-
#### Android
97-
98-
1. ???
91+
Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding.
9992

10093
### Run in the simulator
10194

android/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Android/IntelliJ
6+
#
7+
build/
8+
.idea
9+
.gradle
10+
local.properties
11+
*.iml
12+
*.hprof
13+
14+
# Bundle artifacts
15+
*.jsbundle

android/app/build.gradle

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
apply plugin: "com.android.application"
2+
apply plugin: "com.facebook.react"
3+
4+
def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
5+
6+
/**
7+
* This is the configuration block to customize your React Native Android app.
8+
* By default you don't need to apply any configuration, just uncomment the lines you need.
9+
*/
10+
react {
11+
entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim())
12+
reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
13+
hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc"
14+
codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
15+
16+
// Use Expo CLI to bundle the app, this ensures the Metro config
17+
// works correctly with Expo projects.
18+
cliFile = new File(["node", "--print", "require.resolve('@expo/cli')"].execute(null, rootDir).text.trim())
19+
bundleCommand = "export:embed"
20+
21+
/* Folders */
22+
// The root of your project, i.e. where "package.json" lives. Default is '..'
23+
// root = file("../")
24+
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
25+
// reactNativeDir = file("../node_modules/react-native")
26+
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
27+
// codegenDir = file("../node_modules/@react-native/codegen")
28+
29+
/* Variants */
30+
// The list of variants to that are debuggable. For those we're going to
31+
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
32+
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
33+
// debuggableVariants = ["liteDebug", "prodDebug"]
34+
35+
/* Bundling */
36+
// A list containing the node command and its flags. Default is just 'node'.
37+
// nodeExecutableAndArgs = ["node"]
38+
39+
//
40+
// The path to the CLI configuration file. Default is empty.
41+
// bundleConfig = file(../rn-cli.config.js)
42+
//
43+
// The name of the generated asset file containing your JS bundle
44+
// bundleAssetName = "MyApplication.android.bundle"
45+
//
46+
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
47+
// entryFile = file("../js/MyApplication.android.js")
48+
//
49+
// A list of extra flags to pass to the 'bundle' commands.
50+
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
51+
// extraPackagerArgs = []
52+
53+
/* Hermes Commands */
54+
// The hermes compiler command to run. By default it is 'hermesc'
55+
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
56+
//
57+
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
58+
// hermesFlags = ["-O", "-output-source-map"]
59+
}
60+
61+
/**
62+
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
63+
*/
64+
def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: false).toBoolean()
65+
66+
/**
67+
* The preferred build flavor of JavaScriptCore (JSC)
68+
*
69+
* For example, to use the international variant, you can use:
70+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
71+
*
72+
* The international variant includes ICU i18n library and necessary data
73+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
74+
* give correct results when using with locales other than en-US. Note that
75+
* this variant is about 6MiB larger per architecture than default.
76+
*/
77+
def jscFlavor = 'org.webkit:android-jsc:+'
78+
79+
android {
80+
ndkVersion rootProject.ext.ndkVersion
81+
82+
compileSdkVersion rootProject.ext.compileSdkVersion
83+
84+
namespace 'io.libp2p.jslibp2preactnative'
85+
defaultConfig {
86+
applicationId 'io.libp2p.jslibp2preactnative'
87+
minSdkVersion rootProject.ext.minSdkVersion
88+
targetSdkVersion rootProject.ext.targetSdkVersion
89+
versionCode 1
90+
versionName "1.0.0"
91+
92+
buildConfigField("boolean", "REACT_NATIVE_UNSTABLE_USE_RUNTIME_SCHEDULER_ALWAYS", (findProperty("reactNative.unstable_useRuntimeSchedulerAlways") ?: true).toString())
93+
}
94+
signingConfigs {
95+
debug {
96+
storeFile file('debug.keystore')
97+
storePassword 'android'
98+
keyAlias 'androiddebugkey'
99+
keyPassword 'android'
100+
}
101+
}
102+
buildTypes {
103+
debug {
104+
signingConfig signingConfigs.debug
105+
}
106+
release {
107+
// Caution! In production, you need to generate your own keystore file.
108+
// see https://reactnative.dev/docs/signed-apk-android.
109+
signingConfig signingConfigs.debug
110+
shrinkResources (findProperty('android.enableShrinkResourcesInReleaseBuilds')?.toBoolean() ?: false)
111+
minifyEnabled enableProguardInReleaseBuilds
112+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
113+
}
114+
}
115+
}
116+
117+
// Apply static values from `gradle.properties` to the `android.packagingOptions`
118+
// Accepts values in comma delimited lists, example:
119+
// android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini
120+
["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
121+
// Split option: 'foo,bar' -> ['foo', 'bar']
122+
def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
123+
// Trim all elements in place.
124+
for (i in 0..<options.size()) options[i] = options[i].trim();
125+
// `[] - ""` is essentially `[""].filter(Boolean)` removing all empty strings.
126+
options -= ""
127+
128+
if (options.length > 0) {
129+
println "android.packagingOptions.$prop += $options ($options.length)"
130+
// Ex: android.packagingOptions.pickFirsts += '**/SCCS/**'
131+
options.each {
132+
android.packagingOptions[prop] += it
133+
}
134+
}
135+
}
136+
137+
dependencies {
138+
// The version of react-native is set by the React Native Gradle Plugin
139+
implementation("com.facebook.react:react-android")
140+
141+
def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
142+
def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
143+
def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";
144+
def frescoVersion = rootProject.ext.frescoVersion
145+
146+
// If your app supports Android versions before Ice Cream Sandwich (API level 14)
147+
if (isGifEnabled || isWebpEnabled) {
148+
implementation("com.facebook.fresco:fresco:${frescoVersion}")
149+
implementation("com.facebook.fresco:imagepipeline-okhttp3:${frescoVersion}")
150+
}
151+
152+
if (isGifEnabled) {
153+
// For animated gif support
154+
implementation("com.facebook.fresco:animated-gif:${frescoVersion}")
155+
}
156+
157+
if (isWebpEnabled) {
158+
// For webp support
159+
implementation("com.facebook.fresco:webpsupport:${frescoVersion}")
160+
if (isWebpAnimatedEnabled) {
161+
// Animated webp support
162+
implementation("com.facebook.fresco:animated-webp:${frescoVersion}")
163+
}
164+
}
165+
166+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
167+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
168+
exclude group:'com.squareup.okhttp3', module:'okhttp'
169+
}
170+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
171+
172+
if (hermesEnabled.toBoolean()) {
173+
implementation("com.facebook.react:hermes-android")
174+
} else {
175+
implementation jscFlavor
176+
}
177+
}
178+
179+
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
180+
applyNativeModulesAppBuildGradle(project)

android/app/debug.keystore

2.2 KB
Binary file not shown.

android/app/proguard-rules.pro

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
# react-native-reanimated
11+
-keep class com.swmansion.reanimated.** { *; }
12+
-keep class com.facebook.react.turbomodule.** { *; }
13+
14+
# Add any project specific keep options here:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools">
3+
4+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
5+
6+
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" tools:replace="android:usesCleartextTraffic" />
7+
</manifest>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and 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 io.libp2p.jslibp2preactnative;
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.sharedpreferences.SharedPreferencesFlipperPlugin;
21+
import com.facebook.react.ReactInstanceEventListener;
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+
/**
28+
* Class responsible of loading Flipper inside your React Native application. This is the debug
29+
* flavor of it. Here you can add your own plugins and customize the Flipper setup.
30+
*/
31+
public class ReactNativeFlipper {
32+
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
33+
if (FlipperUtils.shouldEnableFlipper(context)) {
34+
final FlipperClient client = AndroidFlipperClient.getInstance(context);
35+
36+
client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
37+
client.addPlugin(new DatabasesFlipperPlugin(context));
38+
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
39+
client.addPlugin(CrashReporterPlugin.getInstance());
40+
41+
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
42+
NetworkingModule.setCustomClientBuilder(
43+
new NetworkingModule.CustomClientBuilder() {
44+
@Override
45+
public void apply(OkHttpClient.Builder builder) {
46+
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
47+
}
48+
});
49+
client.addPlugin(networkFlipperPlugin);
50+
client.start();
51+
52+
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
53+
// Hence we run if after all native modules have been initialized
54+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
55+
if (reactContext == null) {
56+
reactInstanceManager.addReactInstanceEventListener(
57+
new ReactInstanceEventListener() {
58+
@Override
59+
public void onReactContextInitialized(ReactContext reactContext) {
60+
reactInstanceManager.removeReactInstanceEventListener(this);
61+
reactContext.runOnNativeModulesQueueThread(
62+
new Runnable() {
63+
@Override
64+
public void run() {
65+
client.addPlugin(new FrescoFlipperPlugin());
66+
}
67+
});
68+
}
69+
});
70+
} else {
71+
client.addPlugin(new FrescoFlipperPlugin());
72+
}
73+
}
74+
}
75+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.INTERNET"/>
3+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
4+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
5+
<uses-permission android:name="android.permission.VIBRATE"/>
6+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
7+
<queries>
8+
<intent>
9+
<action android:name="android.intent.action.VIEW"/>
10+
<category android:name="android.intent.category.BROWSABLE"/>
11+
<data android:scheme="https"/>
12+
</intent>
13+
</queries>
14+
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme">
15+
<meta-data android:name="expo.modules.updates.ENABLED" android:value="false"/>
16+
<meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="49.0.0"/>
17+
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
18+
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
19+
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN"/>
22+
<category android:name="android.intent.category.LAUNCHER"/>
23+
</intent-filter>
24+
<intent-filter>
25+
<action android:name="android.intent.action.VIEW"/>
26+
<category android:name="android.intent.category.DEFAULT"/>
27+
<category android:name="android.intent.category.BROWSABLE"/>
28+
<data android:scheme="io.libp2p.jslibp2preactnative"/>
29+
</intent-filter>
30+
</activity>
31+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/>
32+
</application>
33+
</manifest>

0 commit comments

Comments
 (0)