mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	| @@ -1,226 +1,87 @@ | ||||
| plugins { | ||||
|     id 'com.android.application' | ||||
|     id 'org.jetbrains.kotlin.android' | ||||
| apply plugin: "com.android.application" | ||||
| apply plugin: "com.facebook.react" | ||||
| apply plugin: "kotlin-android" | ||||
| apply plugin: "kotlin-android-extensions" | ||||
|  | ||||
| /** | ||||
|  * This is the configuration block to customize your React Native Android app. | ||||
|  * By default you don't need to apply any configuration, just uncomment the lines you need. | ||||
|  */ | ||||
| react { | ||||
|     /* Folders */ | ||||
|     //   The root of your project, i.e. where "package.json" lives. Default is '..' | ||||
|     // root = file("../") | ||||
|     //   The folder where the react-native NPM package is. Default is ../node_modules/react-native | ||||
|     // reactNativeDir = file("../node_modules/react-native") | ||||
|     //   The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen | ||||
|     // codegenDir = file("../node_modules/@react-native/codegen") | ||||
|     //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js | ||||
|     // cliFile = file("../node_modules/react-native/cli.js") | ||||
|  | ||||
|     /* Variants */ | ||||
|     //   The list of variants to that are debuggable. For those we're going to | ||||
|     //   skip the bundling of the JS bundle and the assets. By default is just 'debug'. | ||||
|     //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. | ||||
|     // debuggableVariants = ["liteDebug", "prodDebug"] | ||||
|  | ||||
|     /* Bundling */ | ||||
|     //   A list containing the node command and its flags. Default is just 'node'. | ||||
|     // nodeExecutableAndArgs = ["node"] | ||||
|     // | ||||
|     //   The command to run when bundling. By default is 'bundle' | ||||
|     // bundleCommand = "ram-bundle" | ||||
|     // | ||||
|     //   The path to the CLI configuration file. Default is empty. | ||||
|     // bundleConfig = file(../rn-cli.config.js) | ||||
|     // | ||||
|     //   The name of the generated asset file containing your JS bundle | ||||
|     // bundleAssetName = "MyApplication.android.bundle" | ||||
|     // | ||||
|     //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js' | ||||
|     // entryFile = file("../js/MyApplication.android.js") | ||||
|     // | ||||
|     //   A list of extra flags to pass to the 'bundle' commands. | ||||
|     //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle | ||||
|     // extraPackagerArgs = [] | ||||
|  | ||||
|     /* Hermes Commands */ | ||||
|     //   The hermes compiler command to run. By default it is 'hermesc' | ||||
|     // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" | ||||
|     // | ||||
|     //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" | ||||
|     // hermesFlags = ["-O", "-output-source-map"] | ||||
| } | ||||
|  | ||||
| import com.android.build.OutputFile | ||||
|  | ||||
| /** | ||||
|  * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets | ||||
|  * and bundleReleaseJsAndAssets). | ||||
|  * These basically call `react-native bundle` with the correct arguments during the Android build | ||||
|  * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the | ||||
|  * bundle directly from the development server. Below you can see all the possible configurations | ||||
|  * and their defaults. If you decide to add a configuration block, make sure to add it before the | ||||
|  * `apply from: "../../node_modules/react-native/react.gradle"` line. | ||||
|  * | ||||
|  * project.ext.react = [ | ||||
|  *   // the name of the generated asset file containing your JS bundle | ||||
|  *   bundleAssetName: "index.android.bundle", | ||||
|  * | ||||
|  *   // the entry file for bundle generation. If none specified and | ||||
|  *   // "index.android.js" exists, it will be used. Otherwise "index.js" is | ||||
|  *   // default. Can be overridden with ENTRY_FILE environment variable. | ||||
|  *   entryFile: "index.android.js", | ||||
|  * | ||||
|  *   // https://reactnative.dev/docs/performance#enable-the-ram-format | ||||
|  *   bundleCommand: "ram-bundle", | ||||
|  * | ||||
|  *   // whether to bundle JS and assets in debug mode | ||||
|  *   bundleInDebug: false, | ||||
|  * | ||||
|  *   // whether to bundle JS and assets in release mode | ||||
|  *   bundleInRelease: true, | ||||
|  * | ||||
|  *   // whether to bundle JS and assets in another build variant (if configured). | ||||
|  *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants | ||||
|  *   // The configuration property can be in the following formats | ||||
|  *   //         'bundleIn${productFlavor}${buildType}' | ||||
|  *   //         'bundleIn${buildType}' | ||||
|  *   // bundleInFreeDebug: true, | ||||
|  *   // bundleInPaidRelease: true, | ||||
|  *   // bundleInBeta: true, | ||||
|  * | ||||
|  *   // whether to disable dev mode in custom build variants (by default only disabled in release) | ||||
|  *   // for example: to disable dev mode in the staging build type (if configured) | ||||
|  *   devDisabledInStaging: true, | ||||
|  *   // The configuration property can be in the following formats | ||||
|  *   //         'devDisabledIn${productFlavor}${buildType}' | ||||
|  *   //         'devDisabledIn${buildType}' | ||||
|  * | ||||
|  *   // the root of your project, i.e. where "package.json" lives | ||||
|  *   root: "../../", | ||||
|  * | ||||
|  *   // where to put the JS bundle asset in debug mode | ||||
|  *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug", | ||||
|  * | ||||
|  *   // where to put the JS bundle asset in release mode | ||||
|  *   jsBundleDirRelease: "$buildDir/intermediates/assets/release", | ||||
|  * | ||||
|  *   // where to put drawable resources / React Native assets, e.g. the ones you use via | ||||
|  *   // require('./image.png')), in debug mode | ||||
|  *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", | ||||
|  * | ||||
|  *   // where to put drawable resources / React Native assets, e.g. the ones you use via | ||||
|  *   // require('./image.png')), in release mode | ||||
|  *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release", | ||||
|  * | ||||
|  *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means | ||||
|  *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to | ||||
|  *   // date; if you have any other folders that you want to ignore for performance reasons (gradle | ||||
|  *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ | ||||
|  *   // for example, you might want to remove it from here. | ||||
|  *   inputExcludes: ["android/**", "ios/**"], | ||||
|  * | ||||
|  *   // override which node gets called and with what additional arguments | ||||
|  *   nodeExecutableAndArgs: ["node"], | ||||
|  * | ||||
|  *   // supply additional arguments to the packager | ||||
|  *   extraPackagerArgs: [] | ||||
|  * ] | ||||
|  */ | ||||
|  | ||||
| project.ext.react = [ | ||||
|     enableHermes: false,  // clean and rebuild if changing | ||||
| ] | ||||
|  | ||||
| apply from: "../../node_modules/react-native/react.gradle" | ||||
|  | ||||
| /** | ||||
|  * Set this to true to create two separate APKs instead of one: | ||||
|  *   - An APK that only works on ARM devices | ||||
|  *   - An APK that only works on x86 devices | ||||
|  * The advantage is the size of the APK is reduced by about 4MB. | ||||
|  * Upload all the APKs to the Play Store and people will download | ||||
|  * the correct one based on the CPU architecture of their device. | ||||
|  */ | ||||
| def enableSeparateBuildPerCPUArchitecture = true | ||||
|  | ||||
| /** | ||||
|  * Run Proguard to shrink the Java bytecode in release builds. | ||||
|  * Set this to true to Run Proguard on Release builds to minify the Java bytecode. | ||||
|  */ | ||||
| def enableProguardInReleaseBuilds = false | ||||
|  | ||||
| /** | ||||
|  * The preferred build flavor of JavaScriptCore. | ||||
|  * The preferred build flavor of JavaScriptCore (JSC) | ||||
|  * | ||||
|  * For example, to use the international variant, you can use: | ||||
|  * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` | ||||
|  * | ||||
|  * The international variant includes ICU i18n library and necessary data | ||||
|  * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that | ||||
|  * give correct results when using with locales other than en-US.  Note that | ||||
|  * give correct results when using with locales other than en-US. Note that | ||||
|  * this variant is about 6MiB larger per architecture than default. | ||||
|  */ | ||||
| def jscFlavor = 'org.webkit:android-jsc:+' | ||||
|  | ||||
| /** | ||||
|  * Whether to enable the Hermes VM. | ||||
|  * | ||||
|  * This should be set on project.ext.react and that value will be read here. If it is not set | ||||
|  * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode | ||||
|  * and the benefits of using Hermes will therefore be sharply reduced. | ||||
|  */ | ||||
| def enableHermes = project.ext.react.get("enableHermes", false); | ||||
|  | ||||
| /** | ||||
|  * Architectures to build native code for. | ||||
|  */ | ||||
| def reactNativeArchitectures() { | ||||
|     def value = project.getProperties().get("reactNativeArchitectures") | ||||
|     return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] | ||||
| } | ||||
|  | ||||
| android { | ||||
|     ndkVersion rootProject.ext.ndkVersion | ||||
|  | ||||
|     compileSdkVersion rootProject.ext.compileSdkVersion | ||||
|  | ||||
|     namespace "com.awesomeproject" | ||||
|     defaultConfig { | ||||
|         applicationId "com.awesomeproject" | ||||
|         minSdkVersion rootProject.ext.minSdkVersion | ||||
|         targetSdkVersion rootProject.ext.targetSdkVersion | ||||
|         versionCode 1 | ||||
|         versionName "2.0" | ||||
|         testBuildType System.getProperty('testBuildType', 'debug') | ||||
|         testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' | ||||
|         buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() | ||||
|  | ||||
|         if (isNewArchitectureEnabled()) { | ||||
|             // We configure the NDK build only if you decide to opt-in for the New Architecture. | ||||
|             externalNativeBuild { | ||||
|                 ndkBuild { | ||||
|                     arguments "APP_PLATFORM=android-21", | ||||
|                         "APP_STL=c++_shared", | ||||
|                         "NDK_TOOLCHAIN_VERSION=clang", | ||||
|                         "GENERATED_SRC_DIR=$buildDir/generated/source", | ||||
|                         "PROJECT_BUILD_DIR=$buildDir", | ||||
|                         "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid", | ||||
|                         "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build", | ||||
|                         "NODE_MODULES_DIR=$rootDir/../node_modules" | ||||
|                     cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" | ||||
|                     cppFlags "-std=c++17" | ||||
|                     // Make sure this target name is the same you specify inside the | ||||
|                     // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable. | ||||
|                     targets "awesomeproject_appmodules" | ||||
|                 } | ||||
|             } | ||||
|             if (!enableSeparateBuildPerCPUArchitecture) { | ||||
|                 ndk { | ||||
|                     abiFilters (*reactNativeArchitectures()) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     if (isNewArchitectureEnabled()) { | ||||
|         // We configure the NDK build only if you decide to opt-in for the New Architecture. | ||||
|         externalNativeBuild { | ||||
|             ndkBuild { | ||||
|                 path "$projectDir/src/main/jni/Android.mk" | ||||
|             } | ||||
|         } | ||||
|         def reactAndroidProjectDir = project(':ReactAndroid').projectDir | ||||
|         def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) { | ||||
|             dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck") | ||||
|             from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") | ||||
|             into("$buildDir/react-ndk/exported") | ||||
|         } | ||||
|         def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) { | ||||
|             dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck") | ||||
|             from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") | ||||
|             into("$buildDir/react-ndk/exported") | ||||
|         } | ||||
|         afterEvaluate { | ||||
|             // If you wish to add a custom TurboModule or component locally, | ||||
|             // you should uncomment this line. | ||||
|             // preBuild.dependsOn("generateCodegenArtifactsFromSchema") | ||||
|             preDebugBuild.dependsOn(packageReactNdkDebugLibs) | ||||
|             preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) | ||||
|  | ||||
|             // Due to a bug inside AGP, we have to explicitly set a dependency | ||||
|             // between configureNdkBuild* tasks and the preBuild tasks. | ||||
|             // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732 | ||||
|             configureNdkBuildRelease.dependsOn(preReleaseBuild) | ||||
|             configureNdkBuildDebug.dependsOn(preDebugBuild) | ||||
|             reactNativeArchitectures().each { architecture -> | ||||
|                 tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure { | ||||
|                     dependsOn("preDebugBuild") | ||||
|                 } | ||||
|                 tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure { | ||||
|                     dependsOn("preReleaseBuild") | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     splits { | ||||
|         abi { | ||||
|             reset() | ||||
|             enable enableSeparateBuildPerCPUArchitecture | ||||
|             universalApk false  // If true, also generate a universal APK | ||||
|             include (*reactNativeArchitectures()) | ||||
|         } | ||||
|         versionName "1.0" | ||||
|     } | ||||
|     signingConfigs { | ||||
|         debug { | ||||
| @@ -237,93 +98,28 @@ android { | ||||
|         release { | ||||
|             // Caution! In production, you need to generate your own keystore file. | ||||
|             // see https://reactnative.dev/docs/signed-apk-android. | ||||
|             crunchPngs false | ||||
|             signingConfig signingConfigs.debug | ||||
|             minifyEnabled enableProguardInReleaseBuilds | ||||
|             proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" | ||||
|             proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro" | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // applicationVariants are e.g. debug, release | ||||
|     applicationVariants.all { variant -> | ||||
|         variant.outputs.each { output -> | ||||
|             // For each separate APK per architecture, set a unique version code as described here: | ||||
|             // https://developer.android.com/studio/build/configure-apk-splits.html | ||||
|             // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. | ||||
|             def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] | ||||
|             def abi = output.getFilter(OutputFile.ABI) | ||||
|             if (abi != null) {  // null for the universal-debug, universal-release variants | ||||
|                 output.versionCodeOverride = | ||||
|                         defaultConfig.versionCode * 1000 + versionCodes.get(abi) | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| dependencies { | ||||
|     androidTestImplementation('com.wix:detox:+') | ||||
|     implementation 'androidx.appcompat:appcompat:1.1.0' | ||||
|     implementation fileTree(dir: "libs", include: ["*.jar"]) | ||||
|  | ||||
|     //noinspection GradleDynamicVersion | ||||
|     implementation "com.facebook.react:react-native:+"  // From node_modules | ||||
|  | ||||
|     implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" | ||||
|  | ||||
|     debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { | ||||
|         exclude group:'com.facebook.fbjni' | ||||
|     } | ||||
|     // The version of react-native is set by the React Native Gradle Plugin | ||||
|     implementation("com.facebook.react:react-android") | ||||
|  | ||||
|     debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") | ||||
|     debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { | ||||
|         exclude group:'com.facebook.flipper' | ||||
|         exclude group:'com.squareup.okhttp3', module:'okhttp' | ||||
|     } | ||||
|  | ||||
|     debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { | ||||
|         exclude group:'com.facebook.flipper' | ||||
|     } | ||||
|  | ||||
|     if (enableHermes) { | ||||
|         //noinspection GradleDynamicVersion | ||||
|         implementation("com.facebook.react:hermes-engine:+") { // From node_modules | ||||
|             exclude group:'com.facebook.fbjni' | ||||
|         } | ||||
|     debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") | ||||
|     if (hermesEnabled.toBoolean()) { | ||||
|         implementation("com.facebook.react:hermes-android") | ||||
|     } else { | ||||
|         implementation jscFlavor | ||||
|     } | ||||
| } | ||||
|  | ||||
| if (isNewArchitectureEnabled()) { | ||||
|     // If new architecture is enabled, we let you build RN from source | ||||
|     // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. | ||||
|     // This will be applied to all the imported transtitive dependency. | ||||
|     configurations.all { | ||||
|         resolutionStrategy.dependencySubstitution { | ||||
|             substitute(module("com.facebook.react:react-native")) | ||||
|                     .using(project(":ReactAndroid")) | ||||
|                     .because("On New Architecture we're building React Native from source") | ||||
|             substitute(module("com.facebook.react:hermes-engine")) | ||||
|                     .using(project(":ReactAndroid:hermes-engine")) | ||||
|                     .because("On New Architecture we're building Hermes from source") | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| // Run this once to be able to run the application with BUCK | ||||
| // puts all compile dependencies into folder libs for BUCK to use | ||||
| task copyDownloadableDepsToLibs(type: Copy) { | ||||
|     from configurations.implementation | ||||
|     into 'libs' | ||||
| } | ||||
|  | ||||
| apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) | ||||
|  | ||||
| def isNewArchitectureEnabled() { | ||||
|     // To opt-in for the New Architecture, you can either: | ||||
|     // - Set `newArchEnabled` to true inside the `gradle.properties` file | ||||
|     // - Invoke gradle with `-newArchEnabled=true` | ||||
|     // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` | ||||
|     return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" | ||||
| } | ||||
|   | ||||
| @@ -2,7 +2,8 @@ package com.awesomeproject; | ||||
|  | ||||
| import com.facebook.react.ReactActivity; | ||||
| import com.facebook.react.ReactActivityDelegate; | ||||
| import com.facebook.react.ReactRootView; | ||||
| import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; | ||||
| import com.facebook.react.defaults.DefaultReactActivityDelegate; | ||||
|  | ||||
| public class MainActivity extends ReactActivity { | ||||
|  | ||||
| @@ -16,33 +17,16 @@ public class MainActivity extends ReactActivity { | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and | ||||
|    * you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer | ||||
|    * (Paper). | ||||
|    * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link | ||||
|    * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React | ||||
|    * (aka React 18) with two boolean flags. | ||||
|    */ | ||||
|   @Override | ||||
|   protected ReactActivityDelegate createReactActivityDelegate() { | ||||
|     return new MainActivityDelegate(this, getMainComponentName()); | ||||
|   } | ||||
|  | ||||
|   public static class MainActivityDelegate extends ReactActivityDelegate { | ||||
|     public MainActivityDelegate(ReactActivity activity, String mainComponentName) { | ||||
|       super(activity, mainComponentName); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected ReactRootView createRootView() { | ||||
|       ReactRootView reactRootView = new ReactRootView(getContext()); | ||||
|       // If you opted-in for the New Architecture, we enable the Fabric Renderer. | ||||
|       reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); | ||||
|       return reactRootView; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected boolean isConcurrentRootEnabled() { | ||||
|       // If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18). | ||||
|       // More on this on https://reactjs.org/blog/2022/03/29/react-v18.html | ||||
|       return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||||
|     } | ||||
|     return new DefaultReactActivityDelegate( | ||||
|         this, | ||||
|         getMainComponentName(), | ||||
|         // If you opted-in for the New Architecture, we enable the Fabric Renderer. | ||||
|         DefaultNewArchitectureEntryPoint.getFabricEnabled()); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,104 +1,70 @@ | ||||
| package com.awesomeproject; | ||||
|  | ||||
| import android.app.Application; | ||||
| import android.content.Context; | ||||
|  | ||||
| import androidx.annotation.Nullable; | ||||
|  | ||||
| import com.facebook.react.PackageList; | ||||
| import com.facebook.react.ReactApplication; | ||||
| import com.facebook.react.ReactInstanceManager; | ||||
| import com.facebook.react.ReactNativeHost; | ||||
| import com.facebook.react.ReactPackage; | ||||
| import com.facebook.react.config.ReactFeatureFlags; | ||||
| import com.facebook.react.shell.MainReactPackage; | ||||
| import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; | ||||
| import com.facebook.react.defaults.DefaultReactNativeHost; | ||||
| import com.facebook.soloader.SoLoader; | ||||
| import com.awesomeproject.newarchitecture.MainApplicationReactNativeHost; | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
| import cn.reactnative.modules.update.UpdateContext; | ||||
| import cn.reactnative.modules.update.UpdatePackage; | ||||
|  | ||||
| public class MainApplication extends Application implements ReactApplication { | ||||
|  | ||||
|     private final ReactNativeHost mReactNativeHost = | ||||
|             new ReactNativeHost(this) { | ||||
|                 @Override | ||||
|                 public boolean getUseDeveloperSupport() { | ||||
|                     return BuildConfig.DEBUG; | ||||
|                 } | ||||
|   private final ReactNativeHost mReactNativeHost = | ||||
|       new DefaultReactNativeHost(this) { | ||||
|           @Override | ||||
|           public boolean getUseDeveloperSupport() { | ||||
|               return BuildConfig.DEBUG; | ||||
|           } | ||||
|  | ||||
|                 @Nullable | ||||
|                 @Override | ||||
|                 protected String getJSBundleFile() { | ||||
|                     return UpdateContext.getBundleUrl(MainApplication.this); | ||||
|                 } | ||||
|           @Override | ||||
|           protected String getJSBundleFile() { | ||||
|               return UpdateContext.getBundleUrl(MainApplication.this); | ||||
|           } | ||||
|  | ||||
|                 @Override | ||||
|                 protected List<ReactPackage> getPackages() { | ||||
|                     @SuppressWarnings("UnnecessaryLocalVariable") | ||||
|                     List<ReactPackage> packages = new PackageList(this).getPackages(); | ||||
|                     // Packages that cannot be autolinked yet can be added manually here, for example: | ||||
|                     // packages.add(new MyReactNativePackage()); | ||||
|                     return packages; | ||||
|                 } | ||||
|           @Override | ||||
|           protected List<ReactPackage> getPackages() { | ||||
|               @SuppressWarnings("UnnecessaryLocalVariable") | ||||
|               List<ReactPackage> packages = new PackageList(this).getPackages(); | ||||
|               // Packages that cannot be autolinked yet can be added manually here, for example: | ||||
|               // packages.add(new MyReactNativePackage()); | ||||
|               return packages; | ||||
|           } | ||||
|  | ||||
|                 @Override | ||||
|                 protected String getJSMainModuleName() { | ||||
|                     return "index"; | ||||
|                 } | ||||
|             }; | ||||
|           @Override | ||||
|           protected boolean isNewArchEnabled() { | ||||
|               return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||||
|           } | ||||
|  | ||||
|           @Override | ||||
|           protected Boolean isHermesEnabled() { | ||||
|               return BuildConfig.IS_HERMES_ENABLED; | ||||
|           } | ||||
|  | ||||
|  | ||||
|           @Override | ||||
|           protected String getJSMainModuleName() { | ||||
|               return "index"; | ||||
|           } | ||||
|       }; | ||||
|  | ||||
|   private final ReactNativeHost mNewArchitectureNativeHost = | ||||
|       new MainApplicationReactNativeHost(this); | ||||
|  | ||||
|   @Override | ||||
|   public ReactNativeHost getReactNativeHost() { | ||||
|     if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||||
|       return mNewArchitectureNativeHost; | ||||
|     } else { | ||||
|       return mReactNativeHost; | ||||
|     } | ||||
|     return mReactNativeHost; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public void onCreate() { | ||||
|     super.onCreate(); | ||||
|     // If you opted-in for the New Architecture, we enable the TurboModule system | ||||
|     ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||||
|     SoLoader.init(this, /* native exopackage */ false); | ||||
|     initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Loads Flipper in React Native templates. Call this in the onCreate method with something like | ||||
|    * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); | ||||
|    * | ||||
|    * @param context | ||||
|    * @param reactInstanceManager | ||||
|    */ | ||||
|   private static void initializeFlipper( | ||||
|       Context context, ReactInstanceManager reactInstanceManager) { | ||||
|     if (BuildConfig.DEBUG) { | ||||
|       try { | ||||
|         /* | ||||
|          We use reflection here to pick up the class that initializes Flipper, | ||||
|         since Flipper library is not available in release mode | ||||
|         */ | ||||
|         Class<?> aClass = Class.forName("com.awesomeproject.ReactNativeFlipper"); | ||||
|         aClass | ||||
|             .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) | ||||
|             .invoke(null, context, reactInstanceManager); | ||||
|       } catch (ClassNotFoundException e) { | ||||
|         e.printStackTrace(); | ||||
|       } catch (NoSuchMethodException e) { | ||||
|         e.printStackTrace(); | ||||
|       } catch (IllegalAccessException e) { | ||||
|         e.printStackTrace(); | ||||
|       } catch (InvocationTargetException e) { | ||||
|         e.printStackTrace(); | ||||
|       } | ||||
|     if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||||
|       // If you opted-in for the New Architecture, we load the native entry point for this app. | ||||
|       DefaultNewArchitectureEntryPoint.load(); | ||||
|     } | ||||
|     ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,116 +0,0 @@ | ||||
| package com.awesomeproject.newarchitecture; | ||||
|  | ||||
| import android.app.Application; | ||||
| import androidx.annotation.NonNull; | ||||
| import com.facebook.react.PackageList; | ||||
| import com.facebook.react.ReactInstanceManager; | ||||
| import com.facebook.react.ReactNativeHost; | ||||
| import com.facebook.react.ReactPackage; | ||||
| import com.facebook.react.ReactPackageTurboModuleManagerDelegate; | ||||
| import com.facebook.react.bridge.JSIModulePackage; | ||||
| import com.facebook.react.bridge.JSIModuleProvider; | ||||
| import com.facebook.react.bridge.JSIModuleSpec; | ||||
| import com.facebook.react.bridge.JSIModuleType; | ||||
| import com.facebook.react.bridge.JavaScriptContextHolder; | ||||
| import com.facebook.react.bridge.ReactApplicationContext; | ||||
| import com.facebook.react.bridge.UIManager; | ||||
| import com.facebook.react.fabric.ComponentFactory; | ||||
| import com.facebook.react.fabric.CoreComponentsRegistry; | ||||
| import com.facebook.react.fabric.FabricJSIModuleProvider; | ||||
| import com.facebook.react.fabric.ReactNativeConfig; | ||||
| import com.facebook.react.uimanager.ViewManagerRegistry; | ||||
| import com.awesomeproject.BuildConfig; | ||||
| import com.awesomeproject.newarchitecture.components.MainComponentsRegistry; | ||||
| import com.awesomeproject.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both | ||||
|  * TurboModule delegates and the Fabric Renderer. | ||||
|  * | ||||
|  * <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the | ||||
|  * `newArchEnabled` property). Is ignored otherwise. | ||||
|  */ | ||||
| public class MainApplicationReactNativeHost extends ReactNativeHost { | ||||
|   public MainApplicationReactNativeHost(Application application) { | ||||
|     super(application); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public boolean getUseDeveloperSupport() { | ||||
|     return BuildConfig.DEBUG; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   protected List<ReactPackage> getPackages() { | ||||
|     List<ReactPackage> packages = new PackageList(this).getPackages(); | ||||
|     // Packages that cannot be autolinked yet can be added manually here, for example: | ||||
|     //     packages.add(new MyReactNativePackage()); | ||||
|     // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: | ||||
|     //     packages.add(new TurboReactPackage() { ... }); | ||||
|     // If you have custom Fabric Components, their ViewManagers should also be loaded here | ||||
|     // inside a ReactPackage. | ||||
|     return packages; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   protected String getJSMainModuleName() { | ||||
|     return "index"; | ||||
|   } | ||||
|  | ||||
|   @NonNull | ||||
|   @Override | ||||
|   protected ReactPackageTurboModuleManagerDelegate.Builder | ||||
|       getReactPackageTurboModuleManagerDelegateBuilder() { | ||||
|     // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary | ||||
|     // for the new architecture and to use TurboModules correctly. | ||||
|     return new MainApplicationTurboModuleManagerDelegate.Builder(); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   protected JSIModulePackage getJSIModulePackage() { | ||||
|     return new JSIModulePackage() { | ||||
|       @Override | ||||
|       public List<JSIModuleSpec> getJSIModules( | ||||
|           final ReactApplicationContext reactApplicationContext, | ||||
|           final JavaScriptContextHolder jsContext) { | ||||
|         final List<JSIModuleSpec> specs = new ArrayList<>(); | ||||
|  | ||||
|         // Here we provide a new JSIModuleSpec that will be responsible of providing the | ||||
|         // custom Fabric Components. | ||||
|         specs.add( | ||||
|             new JSIModuleSpec() { | ||||
|               @Override | ||||
|               public JSIModuleType getJSIModuleType() { | ||||
|                 return JSIModuleType.UIManager; | ||||
|               } | ||||
|  | ||||
|               @Override | ||||
|               public JSIModuleProvider<UIManager> getJSIModuleProvider() { | ||||
|                 final ComponentFactory componentFactory = new ComponentFactory(); | ||||
|                 CoreComponentsRegistry.register(componentFactory); | ||||
|  | ||||
|                 // Here we register a Components Registry. | ||||
|                 // The one that is generated with the template contains no components | ||||
|                 // and just provides you the one from React Native core. | ||||
|                 MainComponentsRegistry.register(componentFactory); | ||||
|  | ||||
|                 final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); | ||||
|  | ||||
|                 ViewManagerRegistry viewManagerRegistry = | ||||
|                     new ViewManagerRegistry( | ||||
|                         reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); | ||||
|  | ||||
|                 return new FabricJSIModuleProvider( | ||||
|                     reactApplicationContext, | ||||
|                     componentFactory, | ||||
|                     ReactNativeConfig.DEFAULT_CONFIG, | ||||
|                     viewManagerRegistry); | ||||
|               } | ||||
|             }); | ||||
|         return specs; | ||||
|       } | ||||
|     }; | ||||
|   } | ||||
| } | ||||
| @@ -1,36 +0,0 @@ | ||||
| package com.awesomeproject.newarchitecture.components; | ||||
|  | ||||
| import com.facebook.jni.HybridData; | ||||
| import com.facebook.proguard.annotations.DoNotStrip; | ||||
| import com.facebook.react.fabric.ComponentFactory; | ||||
| import com.facebook.soloader.SoLoader; | ||||
|  | ||||
| /** | ||||
|  * Class responsible to load the custom Fabric Components. This class has native methods and needs a | ||||
|  * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ | ||||
|  * folder for you). | ||||
|  * | ||||
|  * <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the | ||||
|  * `newArchEnabled` property). Is ignored otherwise. | ||||
|  */ | ||||
| @DoNotStrip | ||||
| public class MainComponentsRegistry { | ||||
|   static { | ||||
|     SoLoader.loadLibrary("fabricjni"); | ||||
|   } | ||||
|  | ||||
|   @DoNotStrip private final HybridData mHybridData; | ||||
|  | ||||
|   @DoNotStrip | ||||
|   private native HybridData initHybrid(ComponentFactory componentFactory); | ||||
|  | ||||
|   @DoNotStrip | ||||
|   private MainComponentsRegistry(ComponentFactory componentFactory) { | ||||
|     mHybridData = initHybrid(componentFactory); | ||||
|   } | ||||
|  | ||||
|   @DoNotStrip | ||||
|   public static MainComponentsRegistry register(ComponentFactory componentFactory) { | ||||
|     return new MainComponentsRegistry(componentFactory); | ||||
|   } | ||||
| } | ||||
| @@ -1,48 +0,0 @@ | ||||
| package com.awesomeproject.newarchitecture.modules; | ||||
|  | ||||
| import com.facebook.jni.HybridData; | ||||
| import com.facebook.react.ReactPackage; | ||||
| import com.facebook.react.ReactPackageTurboModuleManagerDelegate; | ||||
| import com.facebook.react.bridge.ReactApplicationContext; | ||||
| import com.facebook.soloader.SoLoader; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * Class responsible to load the TurboModules. This class has native methods and needs a | ||||
|  * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ | ||||
|  * folder for you). | ||||
|  * | ||||
|  * <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the | ||||
|  * `newArchEnabled` property). Is ignored otherwise. | ||||
|  */ | ||||
| public class MainApplicationTurboModuleManagerDelegate | ||||
|     extends ReactPackageTurboModuleManagerDelegate { | ||||
|  | ||||
|   private static volatile boolean sIsSoLibraryLoaded; | ||||
|  | ||||
|   protected MainApplicationTurboModuleManagerDelegate( | ||||
|       ReactApplicationContext reactApplicationContext, List<ReactPackage> packages) { | ||||
|     super(reactApplicationContext, packages); | ||||
|   } | ||||
|  | ||||
|   protected native HybridData initHybrid(); | ||||
|  | ||||
|   native boolean canCreateTurboModule(String moduleName); | ||||
|  | ||||
|   public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder { | ||||
|     protected MainApplicationTurboModuleManagerDelegate build( | ||||
|         ReactApplicationContext context, List<ReactPackage> packages) { | ||||
|       return new MainApplicationTurboModuleManagerDelegate(context, packages); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   protected synchronized void maybeLoadOtherSoLibraries() { | ||||
|     if (!sIsSoLibraryLoaded) { | ||||
|       // If you change the name of your application .so file in the Android.mk file, | ||||
|       // make sure you update the name here as well. | ||||
|       SoLoader.loadLibrary("awesomeproject_appmodules"); | ||||
|       sIsSoLibraryLoaded = true; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @@ -1,48 +0,0 @@ | ||||
| THIS_DIR := $(call my-dir) | ||||
|  | ||||
| include $(REACT_ANDROID_DIR)/Android-prebuilt.mk | ||||
|  | ||||
| # If you wish to add a custom TurboModule or Fabric component in your app you | ||||
| # will have to include the following autogenerated makefile. | ||||
| # include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk | ||||
| include $(CLEAR_VARS) | ||||
|  | ||||
| LOCAL_PATH := $(THIS_DIR) | ||||
|  | ||||
| # You can customize the name of your application .so file here. | ||||
| LOCAL_MODULE := awesomeproject_appmodules | ||||
|  | ||||
| LOCAL_C_INCLUDES := $(LOCAL_PATH) | ||||
| LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) | ||||
| LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) | ||||
|  | ||||
| # If you wish to add a custom TurboModule or Fabric component in your app you | ||||
| # will have to uncomment those lines to include the generated source | ||||
| # files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) | ||||
| # | ||||
| # LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni | ||||
| # LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) | ||||
| # LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni | ||||
|  | ||||
| # Here you should add any native library you wish to depend on. | ||||
| LOCAL_SHARED_LIBRARIES := \ | ||||
|   libfabricjni \ | ||||
|   libfbjni \ | ||||
|   libfolly_runtime \ | ||||
|   libglog \ | ||||
|   libjsi \ | ||||
|   libreact_codegen_rncore \ | ||||
|   libreact_debug \ | ||||
|   libreact_nativemodule_core \ | ||||
|   libreact_render_componentregistry \ | ||||
|   libreact_render_core \ | ||||
|   libreact_render_debug \ | ||||
|   libreact_render_graphics \ | ||||
|   librrc_view \ | ||||
|   libruntimeexecutor \ | ||||
|   libturbomodulejsijni \ | ||||
|   libyoga | ||||
|  | ||||
| LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall | ||||
|  | ||||
| include $(BUILD_SHARED_LIBRARY) | ||||
| @@ -1,24 +0,0 @@ | ||||
| #include "MainApplicationModuleProvider.h" | ||||
|  | ||||
| #include <rncore.h> | ||||
|  | ||||
| namespace facebook { | ||||
| namespace react { | ||||
|  | ||||
| std::shared_ptr<TurboModule> MainApplicationModuleProvider( | ||||
|     const std::string moduleName, | ||||
|     const JavaTurboModule::InitParams ¶ms) { | ||||
|   // Here you can provide your own module provider for TurboModules coming from | ||||
|   // either your application or from external libraries. The approach to follow | ||||
|   // is similar to the following (for a library called `samplelibrary`: | ||||
|   // | ||||
|   // auto module = samplelibrary_ModuleProvider(moduleName, params); | ||||
|   // if (module != nullptr) { | ||||
|   //    return module; | ||||
|   // } | ||||
|   // return rncore_ModuleProvider(moduleName, params); | ||||
|   return rncore_ModuleProvider(moduleName, params); | ||||
| } | ||||
|  | ||||
| } // namespace react | ||||
| } // namespace facebook | ||||
| @@ -1,16 +0,0 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <memory> | ||||
| #include <string> | ||||
|  | ||||
| #include <ReactCommon/JavaTurboModule.h> | ||||
|  | ||||
| namespace facebook { | ||||
| namespace react { | ||||
|  | ||||
| std::shared_ptr<TurboModule> MainApplicationModuleProvider( | ||||
|     const std::string moduleName, | ||||
|     const JavaTurboModule::InitParams ¶ms); | ||||
|  | ||||
| } // namespace react | ||||
| } // namespace facebook | ||||
| @@ -1,45 +0,0 @@ | ||||
| #include "MainApplicationTurboModuleManagerDelegate.h" | ||||
| #include "MainApplicationModuleProvider.h" | ||||
|  | ||||
| namespace facebook { | ||||
| namespace react { | ||||
|  | ||||
| jni::local_ref<MainApplicationTurboModuleManagerDelegate::jhybriddata> | ||||
| MainApplicationTurboModuleManagerDelegate::initHybrid( | ||||
|     jni::alias_ref<jhybridobject>) { | ||||
|   return makeCxxInstance(); | ||||
| } | ||||
|  | ||||
| void MainApplicationTurboModuleManagerDelegate::registerNatives() { | ||||
|   registerHybrid({ | ||||
|       makeNativeMethod( | ||||
|           "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), | ||||
|       makeNativeMethod( | ||||
|           "canCreateTurboModule", | ||||
|           MainApplicationTurboModuleManagerDelegate::canCreateTurboModule), | ||||
|   }); | ||||
| } | ||||
|  | ||||
| std::shared_ptr<TurboModule> | ||||
| MainApplicationTurboModuleManagerDelegate::getTurboModule( | ||||
|     const std::string name, | ||||
|     const std::shared_ptr<CallInvoker> jsInvoker) { | ||||
|   // Not implemented yet: provide pure-C++ NativeModules here. | ||||
|   return nullptr; | ||||
| } | ||||
|  | ||||
| std::shared_ptr<TurboModule> | ||||
| MainApplicationTurboModuleManagerDelegate::getTurboModule( | ||||
|     const std::string name, | ||||
|     const JavaTurboModule::InitParams ¶ms) { | ||||
|   return MainApplicationModuleProvider(name, params); | ||||
| } | ||||
|  | ||||
| bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( | ||||
|     std::string name) { | ||||
|   return getTurboModule(name, nullptr) != nullptr || | ||||
|       getTurboModule(name, {.moduleName = name}) != nullptr; | ||||
| } | ||||
|  | ||||
| } // namespace react | ||||
| } // namespace facebook | ||||
| @@ -1,38 +0,0 @@ | ||||
| #include <memory> | ||||
| #include <string> | ||||
|  | ||||
| #include <ReactCommon/TurboModuleManagerDelegate.h> | ||||
| #include <fbjni/fbjni.h> | ||||
|  | ||||
| namespace facebook { | ||||
| namespace react { | ||||
|  | ||||
| class MainApplicationTurboModuleManagerDelegate | ||||
|     : public jni::HybridClass< | ||||
|           MainApplicationTurboModuleManagerDelegate, | ||||
|           TurboModuleManagerDelegate> { | ||||
|  public: | ||||
|   // Adapt it to the package you used for your Java class. | ||||
|   static constexpr auto kJavaDescriptor = | ||||
|       "Lcom/awesomeproject/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; | ||||
|  | ||||
|   static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>); | ||||
|  | ||||
|   static void registerNatives(); | ||||
|  | ||||
|   std::shared_ptr<TurboModule> getTurboModule( | ||||
|       const std::string name, | ||||
|       const std::shared_ptr<CallInvoker> jsInvoker) override; | ||||
|   std::shared_ptr<TurboModule> getTurboModule( | ||||
|       const std::string name, | ||||
|       const JavaTurboModule::InitParams ¶ms) override; | ||||
|  | ||||
|   /** | ||||
|    * Test-only method. Allows user to verify whether a TurboModule can be | ||||
|    * created by instances of this class. | ||||
|    */ | ||||
|   bool canCreateTurboModule(std::string name); | ||||
| }; | ||||
|  | ||||
| } // namespace react | ||||
| } // namespace facebook | ||||
| @@ -1,61 +0,0 @@ | ||||
| #include "MainComponentsRegistry.h" | ||||
|  | ||||
| #include <CoreComponentsRegistry.h> | ||||
| #include <fbjni/fbjni.h> | ||||
| #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> | ||||
| #include <react/renderer/components/rncore/ComponentDescriptors.h> | ||||
|  | ||||
| namespace facebook { | ||||
| namespace react { | ||||
|  | ||||
| MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} | ||||
|  | ||||
| std::shared_ptr<ComponentDescriptorProviderRegistry const> | ||||
| MainComponentsRegistry::sharedProviderRegistry() { | ||||
|   auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); | ||||
|  | ||||
|   // Custom Fabric Components go here. You can register custom | ||||
|   // components coming from your App or from 3rd party libraries here. | ||||
|   // | ||||
|   // providerRegistry->add(concreteComponentDescriptorProvider< | ||||
|   //        AocViewerComponentDescriptor>()); | ||||
|   return providerRegistry; | ||||
| } | ||||
|  | ||||
| jni::local_ref<MainComponentsRegistry::jhybriddata> | ||||
| MainComponentsRegistry::initHybrid( | ||||
|     jni::alias_ref<jclass>, | ||||
|     ComponentFactory *delegate) { | ||||
|   auto instance = makeCxxInstance(delegate); | ||||
|  | ||||
|   auto buildRegistryFunction = | ||||
|       [](EventDispatcher::Weak const &eventDispatcher, | ||||
|          ContextContainer::Shared const &contextContainer) | ||||
|       -> ComponentDescriptorRegistry::Shared { | ||||
|     auto registry = MainComponentsRegistry::sharedProviderRegistry() | ||||
|                         ->createComponentDescriptorRegistry( | ||||
|                             {eventDispatcher, contextContainer}); | ||||
|  | ||||
|     auto mutableRegistry = | ||||
|         std::const_pointer_cast<ComponentDescriptorRegistry>(registry); | ||||
|  | ||||
|     mutableRegistry->setFallbackComponentDescriptor( | ||||
|         std::make_shared<UnimplementedNativeViewComponentDescriptor>( | ||||
|             ComponentDescriptorParameters{ | ||||
|                 eventDispatcher, contextContainer, nullptr})); | ||||
|  | ||||
|     return registry; | ||||
|   }; | ||||
|  | ||||
|   delegate->buildRegistryFunction = buildRegistryFunction; | ||||
|   return instance; | ||||
| } | ||||
|  | ||||
| void MainComponentsRegistry::registerNatives() { | ||||
|   registerHybrid({ | ||||
|       makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), | ||||
|   }); | ||||
| } | ||||
|  | ||||
| } // namespace react | ||||
| } // namespace facebook | ||||
| @@ -1,32 +0,0 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <ComponentFactory.h> | ||||
| #include <fbjni/fbjni.h> | ||||
| #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> | ||||
| #include <react/renderer/componentregistry/ComponentDescriptorRegistry.h> | ||||
|  | ||||
| namespace facebook { | ||||
| namespace react { | ||||
|  | ||||
| class MainComponentsRegistry | ||||
|     : public facebook::jni::HybridClass<MainComponentsRegistry> { | ||||
|  public: | ||||
|   // Adapt it to the package you used for your Java class. | ||||
|   constexpr static auto kJavaDescriptor = | ||||
|       "Lcom/awesomeproject/newarchitecture/components/MainComponentsRegistry;"; | ||||
|  | ||||
|   static void registerNatives(); | ||||
|  | ||||
|   MainComponentsRegistry(ComponentFactory *delegate); | ||||
|  | ||||
|  private: | ||||
|   static std::shared_ptr<ComponentDescriptorProviderRegistry const> | ||||
|   sharedProviderRegistry(); | ||||
|  | ||||
|   static jni::local_ref<jhybriddata> initHybrid( | ||||
|       jni::alias_ref<jclass>, | ||||
|       ComponentFactory *delegate); | ||||
| }; | ||||
|  | ||||
| } // namespace react | ||||
| } // namespace facebook | ||||
| @@ -1,11 +0,0 @@ | ||||
| #include <fbjni/fbjni.h> | ||||
| #include "MainApplicationTurboModuleManagerDelegate.h" | ||||
| #include "MainComponentsRegistry.h" | ||||
|  | ||||
| JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||||
|   return facebook::jni::initialize(vm, [] { | ||||
|     facebook::react::MainApplicationTurboModuleManagerDelegate:: | ||||
|         registerNatives(); | ||||
|     facebook::react::MainComponentsRegistry::registerNatives(); | ||||
|   }); | ||||
| } | ||||
| @@ -1,59 +1,24 @@ | ||||
| import org.apache.tools.ant.taskdefs.condition.Os | ||||
|  | ||||
| // Top-level build file where you can add configuration options common to all sub-projects/modules. | ||||
|  | ||||
| buildscript { | ||||
|     ext { | ||||
|         buildToolsVersion = "31.0.0" | ||||
|         buildToolsVersion = "33.0.0" | ||||
|         minSdkVersion = 23 | ||||
|         compileSdkVersion = 31 | ||||
|         targetSdkVersion = 31 | ||||
|         kotlinVersion = '1.7.20' | ||||
|         kotlin_version = '1.7.20' | ||||
|         compileSdkVersion = 33 | ||||
|         targetSdkVersion = 33 | ||||
|  | ||||
|         if (System.properties['os.arch'] == "aarch64") { | ||||
|             // For M1 Users we need to use the NDK 24 which added support for aarch64 | ||||
|             ndkVersion = "24.0.8215888" | ||||
|         } else { | ||||
|             // Otherwise we default to the side-by-side NDK version from AGP. | ||||
|             ndkVersion = "21.4.7075529" | ||||
|         } | ||||
|         // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. | ||||
|         ndkVersion = "23.1.7779620" | ||||
|  | ||||
|         kotlin_version = '1.7.20' | ||||
|     } | ||||
|     repositories { | ||||
|         google() | ||||
|         mavenCentral() | ||||
|     } | ||||
|     dependencies { | ||||
|         classpath("com.android.tools.build:gradle:7.1.1") | ||||
|         classpath("com.android.tools.build:gradle") | ||||
|         classpath("com.facebook.react:react-native-gradle-plugin") | ||||
|         classpath("de.undercouch:gradle-download-task:5.0.1") | ||||
|         // NOTE: Do not place your application dependencies here; they belong | ||||
|         // in the individual module build.gradle files | ||||
|         classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") | ||||
|     } | ||||
| } | ||||
|  | ||||
| allprojects { | ||||
|     repositories { | ||||
|         maven { | ||||
|             // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm | ||||
|             url("$rootDir/../node_modules/react-native/android") | ||||
|         } | ||||
|         maven { | ||||
|             // Android JSC is installed from npm | ||||
|             url("$rootDir/../node_modules/jsc-android/dist") | ||||
|         } | ||||
|         mavenCentral { | ||||
|             // We don't want to fetch react-native from Maven Central as there are | ||||
|             // older versions over there. | ||||
|             content { | ||||
|                 excludeGroup "com.facebook.react" | ||||
|             } | ||||
|         } | ||||
|         google() | ||||
|         maven { | ||||
|             url("$rootDir/../node_modules/detox/Detox-android") | ||||
|         } | ||||
|         maven { url 'https://www.jitpack.io' } | ||||
|         classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -25,7 +25,7 @@ android.useAndroidX=true | ||||
| android.enableJetifier=true | ||||
|  | ||||
| # Version of flipper SDK to use with React Native | ||||
| FLIPPER_VERSION=0.125.0 | ||||
| FLIPPER_VERSION=0.182.0 | ||||
|  | ||||
| # Use this property to specify which architecture you want to build. | ||||
| # You can also override it from the CLI using | ||||
| @@ -38,3 +38,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 | ||||
| # to write custom TurboModules/Fabric components OR use libraries that | ||||
| # are providing them. | ||||
| newArchEnabled=false | ||||
|  | ||||
| # Use this property to enable or disable the Hermes JS engine. | ||||
| # If set to false, you will be using JSC instead. | ||||
| hermesEnabled=true | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| distributionBase=GRADLE_USER_HOME | ||||
| distributionPath=wrapper/dists | ||||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip | ||||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip | ||||
| networkTimeout=10000 | ||||
| zipStoreBase=GRADLE_USER_HOME | ||||
| zipStorePath=wrapper/dists | ||||
|   | ||||
							
								
								
									
										18
									
								
								Example/testHotUpdate/android/gradlew
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								Example/testHotUpdate/android/gradlew
									
									
									
									
										vendored
									
									
								
							| @@ -55,7 +55,7 @@ | ||||
| #       Darwin, MinGW, and NonStop. | ||||
| # | ||||
| #   (3) This script is generated from the Groovy template | ||||
| #       https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt | ||||
| #       https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt | ||||
| #       within the Gradle project. | ||||
| # | ||||
| #       You can find Gradle at https://github.com/gradle/gradle/. | ||||
| @@ -80,10 +80,10 @@ do | ||||
|     esac | ||||
| done | ||||
|  | ||||
| APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit | ||||
|  | ||||
| APP_NAME="Gradle" | ||||
| # This is normally unused | ||||
| # shellcheck disable=SC2034 | ||||
| APP_BASE_NAME=${0##*/} | ||||
| APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit | ||||
|  | ||||
| # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||||
| DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' | ||||
| @@ -143,12 +143,16 @@ fi | ||||
| if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then | ||||
|     case $MAX_FD in #( | ||||
|       max*) | ||||
|         # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. | ||||
|         # shellcheck disable=SC3045  | ||||
|         MAX_FD=$( ulimit -H -n ) || | ||||
|             warn "Could not query maximum file descriptor limit" | ||||
|     esac | ||||
|     case $MAX_FD in  #( | ||||
|       '' | soft) :;; #( | ||||
|       *) | ||||
|         # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. | ||||
|         # shellcheck disable=SC3045  | ||||
|         ulimit -n "$MAX_FD" || | ||||
|             warn "Could not set maximum file descriptor limit to $MAX_FD" | ||||
|     esac | ||||
| @@ -205,6 +209,12 @@ set -- \ | ||||
|         org.gradle.wrapper.GradleWrapperMain \ | ||||
|         "$@" | ||||
|  | ||||
| # Stop when "xargs" is not available. | ||||
| if ! command -v xargs >/dev/null 2>&1 | ||||
| then | ||||
|     die "xargs is not available" | ||||
| fi | ||||
|  | ||||
| # Use "xargs" to parse quoted args. | ||||
| # | ||||
| # With -n1 it outputs one arg per line, with the quotes and backslashes removed. | ||||
|   | ||||
							
								
								
									
										15
									
								
								Example/testHotUpdate/android/gradlew.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								Example/testHotUpdate/android/gradlew.bat
									
									
									
									
										vendored
									
									
								
							| @@ -14,7 +14,7 @@ | ||||
| @rem limitations under the License. | ||||
| @rem | ||||
|  | ||||
| @if "%DEBUG%" == "" @echo off | ||||
| @if "%DEBUG%"=="" @echo off | ||||
| @rem ########################################################################## | ||||
| @rem | ||||
| @rem  Gradle startup script for Windows | ||||
| @@ -25,7 +25,8 @@ | ||||
| if "%OS%"=="Windows_NT" setlocal | ||||
|  | ||||
| set DIRNAME=%~dp0 | ||||
| if "%DIRNAME%" == "" set DIRNAME=. | ||||
| if "%DIRNAME%"=="" set DIRNAME=. | ||||
| @rem This is normally unused | ||||
| set APP_BASE_NAME=%~n0 | ||||
| set APP_HOME=%DIRNAME% | ||||
|  | ||||
| @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome | ||||
|  | ||||
| set JAVA_EXE=java.exe | ||||
| %JAVA_EXE% -version >NUL 2>&1 | ||||
| if "%ERRORLEVEL%" == "0" goto execute | ||||
| if %ERRORLEVEL% equ 0 goto execute | ||||
|  | ||||
| echo. | ||||
| echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||||
| @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | ||||
|  | ||||
| :end | ||||
| @rem End local scope for the variables with windows NT shell | ||||
| if "%ERRORLEVEL%"=="0" goto mainEnd | ||||
| if %ERRORLEVEL% equ 0 goto mainEnd | ||||
|  | ||||
| :fail | ||||
| rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | ||||
| rem the _cmd.exe /c_ return code! | ||||
| if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 | ||||
| exit /b 1 | ||||
| set EXIT_CODE=%ERRORLEVEL% | ||||
| if %EXIT_CODE% equ 0 set EXIT_CODE=1 | ||||
| if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% | ||||
| exit /b %EXIT_CODE% | ||||
|  | ||||
| :mainEnd | ||||
| if "%OS%"=="Windows_NT" endlocal | ||||
|   | ||||
| @@ -1,11 +1,4 @@ | ||||
| rootProject.name = 'AwesomeProject' | ||||
| apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) | ||||
| include ':app' | ||||
| includeBuild('../node_modules/react-native-gradle-plugin') | ||||
|  | ||||
| if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") { | ||||
|     include(":ReactAndroid") | ||||
|     project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid') | ||||
|     include(":ReactAndroid:hermes-engine") | ||||
|     project(":ReactAndroid:hermes-engine").projectDir = file('../node_modules/react-native/ReactAndroid/hermes-engine') | ||||
| } | ||||
| includeBuild('../node_modules/@react-native/gradle-plugin') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sunny Luo
					Sunny Luo