diff --git a/Example/testHotUpdate/android/app/build.gradle b/Example/testHotUpdate/android/app/build.gradle index fdf1f82..a8532b3 100644 --- a/Example/testHotUpdate/android/app/build.gradle +++ b/Example/testHotUpdate/android/app/build.gradle @@ -1,7 +1,6 @@ apply plugin: "com.android.application" +apply plugin: "org.jetbrains.kotlin.android" 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. @@ -50,6 +49,7 @@ react { // // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" // hermesFlags = ["-O", "-output-source-map"] + autolinkLibrariesWithApp() } /** @@ -106,21 +106,14 @@ android { } } + dependencies { // 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.squareup.okhttp3', module:'okhttp' - } - - debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") if (hermesEnabled.toBoolean()) { implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor } } - -apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) diff --git a/Example/testHotUpdate/android/app/src/debug/java/com/awesomeproject/ReactNativeFlipper.java b/Example/testHotUpdate/android/app/src/debug/java/com/awesomeproject/ReactNativeFlipper.java deleted file mode 100644 index 0f56fa6..0000000 --- a/Example/testHotUpdate/android/app/src/debug/java/com/awesomeproject/ReactNativeFlipper.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - *

This source code is licensed under the MIT license found in the LICENSE file in the root - * directory of this source tree. - */ -package com.awesomeproject; - -import android.content.Context; -import com.facebook.flipper.android.AndroidFlipperClient; -import com.facebook.flipper.android.utils.FlipperUtils; -import com.facebook.flipper.core.FlipperClient; -import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; -import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; -import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; -import com.facebook.flipper.plugins.inspector.DescriptorMapping; -import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; -import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; -import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; -import com.facebook.flipper.plugins.react.ReactFlipperPlugin; -import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; -import com.facebook.react.ReactInstanceEventListener; -import com.facebook.react.ReactInstanceManager; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.modules.network.NetworkingModule; -import okhttp3.OkHttpClient; - -public class ReactNativeFlipper { - public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { - if (FlipperUtils.shouldEnableFlipper(context)) { - final FlipperClient client = AndroidFlipperClient.getInstance(context); - - client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); - client.addPlugin(new ReactFlipperPlugin()); - client.addPlugin(new DatabasesFlipperPlugin(context)); - client.addPlugin(new SharedPreferencesFlipperPlugin(context)); - client.addPlugin(CrashReporterPlugin.getInstance()); - - NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); - NetworkingModule.setCustomClientBuilder( - new NetworkingModule.CustomClientBuilder() { - @Override - public void apply(OkHttpClient.Builder builder) { - builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); - } - }); - client.addPlugin(networkFlipperPlugin); - client.start(); - - // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized - // Hence we run if after all native modules have been initialized - ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); - if (reactContext == null) { - reactInstanceManager.addReactInstanceEventListener( - new ReactInstanceEventListener() { - @Override - public void onReactContextInitialized(ReactContext reactContext) { - reactInstanceManager.removeReactInstanceEventListener(this); - reactContext.runOnNativeModulesQueueThread( - new Runnable() { - @Override - public void run() { - client.addPlugin(new FrescoFlipperPlugin()); - } - }); - } - }); - } else { - client.addPlugin(new FrescoFlipperPlugin()); - } - } - } -} diff --git a/Example/testHotUpdate/android/app/src/main/java/com/awesomeproject/MainApplication.java b/Example/testHotUpdate/android/app/src/main/java/com/awesomeproject/MainApplication.java index 4f7c8b9..3890b00 100644 --- a/Example/testHotUpdate/android/app/src/main/java/com/awesomeproject/MainApplication.java +++ b/Example/testHotUpdate/android/app/src/main/java/com/awesomeproject/MainApplication.java @@ -65,6 +65,5 @@ public class MainApplication extends Application implements ReactApplication { // If you opted-in for the New Architecture, we load the native entry point for this app. DefaultNewArchitectureEntryPoint.load(); } - ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); } } diff --git a/Example/testHotUpdate/android/build.gradle b/Example/testHotUpdate/android/build.gradle index 92cbde1..a9ea023 100644 --- a/Example/testHotUpdate/android/build.gradle +++ b/Example/testHotUpdate/android/build.gradle @@ -1,15 +1,11 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { ext { - buildToolsVersion = "34.0.0" - minSdkVersion = 23 - compileSdkVersion = 34 + buildToolsVersion = "35.0.0" + minSdkVersion = 24 + compileSdkVersion = 35 targetSdkVersion = 34 ndkVersion = "26.1.10909125" kotlinVersion = "1.9.24" - - kotlin_version = '1.9.24' } repositories { google() @@ -21,3 +17,5 @@ buildscript { classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") } } + +apply plugin: "com.facebook.react.rootproject" diff --git a/Example/testHotUpdate/android/gradle.properties b/Example/testHotUpdate/android/gradle.properties index 885445b..5e24e3a 100644 --- a/Example/testHotUpdate/android/gradle.properties +++ b/Example/testHotUpdate/android/gradle.properties @@ -21,11 +21,6 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m # Android operating system, and which are packaged with your app's APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true - -# Version of flipper SDK to use with React Native -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 diff --git a/Example/testHotUpdate/android/gradlew b/Example/testHotUpdate/android/gradlew index 65dcd68..f5feea6 100755 --- a/Example/testHotUpdate/android/gradlew +++ b/Example/testHotUpdate/android/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,10 +85,9 @@ done # 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"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +134,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +148,7 @@ 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 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/Example/testHotUpdate/android/gradlew.bat b/Example/testHotUpdate/android/gradlew.bat index 6689b85..9b42019 100644 --- a/Example/testHotUpdate/android/gradlew.bat +++ b/Example/testHotUpdate/android/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/Example/testHotUpdate/android/settings.gradle b/Example/testHotUpdate/android/settings.gradle index 37745e9..df43495 100644 --- a/Example/testHotUpdate/android/settings.gradle +++ b/Example/testHotUpdate/android/settings.gradle @@ -1,3 +1,6 @@ +pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") } +plugins { id("com.facebook.react.settings") } +extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } rootProject.name = 'AwesomeProject' apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' diff --git a/Example/testHotUpdate/src/TestConsole.js b/Example/testHotUpdate/src/TestConsole.js index 1243f9d..c2806a4 100644 --- a/Example/testHotUpdate/src/TestConsole.js +++ b/Example/testHotUpdate/src/TestConsole.js @@ -1,7 +1,8 @@ /* eslint-disable react-native/no-inline-styles */ /* eslint-disable react/react-in-jsx-scope */ -import {useCallback, useMemo, useState} from 'react'; +import {useState} from 'react'; import { + Alert, ActivityIndicator, Modal, TextInput, @@ -13,132 +14,127 @@ import { TouchableOpacity, } from 'react-native'; -import {PushyModule} from 'react-native-update'; +import {PushyModule} from 'react-native-update/src/core'; const Hash = '9D5CE6EBA420717BE7E7D308B11F8207681B066C951D68F3994D19828F342474'; const UUID = '00000000-0000-0000-0000-000000000000'; const DownloadUrl = 'http://cos.pgyer.com/697913e94d7441f20c686e2b0996a1aa.apk?sign=7a8f11b1df82cba45c8ac30b1acec88c&t=1680404102&response-content-disposition=attachment%3Bfilename%3DtestHotupdate_1.0.apk'; -const CustomDialog = ({title, visible, onConfirm}) => { - if (!visible) { - return null; - } - - return ( - - - {title} - - 确认 - - - - ); -}; -export default function TestConsole({visible}) { +export default function TestConsole({visible, onClose}) { const [text, setText] = useState(''); const [running, setRunning] = useState(false); - const [options, setOptions] = useState(); - const [alertVisible, setAlertVisible] = useState(false); - const [alertMsg, setAlertMsg] = useState(''); - const NativeTestMethod = useMemo(() => { - return [ + const convertCommands = (cmd, params) => { + if (typeof params === 'string') { + return `${cmd}\n${params}`; + } + let paramText = ''; + for (const [k, v] of Object.entries(params)) { + paramText += `\n${k}\n${v}`; + } + return `${cmd}${paramText}`; + }; + const shortCuts = [ { name: 'setLocalHashInfo', invoke: () => { setText( - `setLocalHashInfo\n${Hash}\n{\"version\":\"1.0.0\",\"size\":\"19M\"}`, + convertCommands('setLocalHashInfo', { + version: '1.0.0', + size: '19M', + }), ); }, }, { name: 'getLocalHashInfo', invoke: () => { - setText(`getLocalHashInfo\n${Hash}`); + setText(convertCommands('getLocalHashInfo', Hash)); }, }, { name: 'setUuid', invoke: () => { - setText(`setUuid\n${UUID}`); + setText(convertCommands('setUuid', UUID)); }, }, { name: 'reloadUpdate', invoke: () => { - setText('reloadUpdate'); - setOptions({hash: Hash}); + setText(convertCommands('reloadUpdate', {hash: Hash})); }, }, { name: 'setNeedUpdate', invoke: () => { - setText('setNeedUpdate'); - setOptions({hash: Hash}); + setText(convertCommands('setNeedUpdate', {hash: Hash})); }, }, { name: 'markSuccess', invoke: () => { - setText('markSuccess'); - setOptions(undefined); + setText(convertCommands('markSuccess')); }, }, { name: 'downloadPatchFromPpk', invoke: () => { - setText('downloadPatchFromPpk'); - setOptions({updateUrl: DownloadUrl, hash: Hash, originHash: Hash}); + setText( + convertCommands('downloadPatchFromPpk', { + updateUrl: DownloadUrl, + hash: Hash, + originHash: Hash, + }), + ); }, }, { name: 'downloadPatchFromPackage', invoke: () => { - setText('downloadPatchFromPackage'); - setOptions({updateUrl: DownloadUrl, hash: Hash}); + setText( + convertCommands('downloadPatchFromPackage', { + updateUrl: DownloadUrl, + hash: Hash, + }), + ); }, }, { name: 'downloadFullUpdate', invoke: () => { - setText('downloadFullUpdate'); - setOptions({updateUrl: DownloadUrl, hash: Hash}); + setText( + convertCommands('downloadFullUpdate', { + updateUrl: DownloadUrl, + hash: Hash, + }), + ); }, }, { name: 'downloadAndInstallApk', invoke: () => { - setText('downloadAndInstallApk'); - setOptions({url: DownloadUrl, target: Hash, hash: Hash}); + setText( + convertCommands('downloadAndInstallApk', { + url: DownloadUrl, + target: Hash, + hash: Hash, + }), + ); }, }, ]; - }, []); - - const renderTestView = useCallback(() => { - const views = []; - for (let i = 0; i < NativeTestMethod.length; i++) { - views.push( - { - NativeTestMethod[i].invoke(); - }}> - {NativeTestMethod[i].name} - , - ); - } - return {views}; - }, [NativeTestMethod]); return ( - 调试Pushy方法(方法名,参数,值换行) + + 调试Pushy方法(方法名,参数,值换行) +