React Native 0.61 版本中的 Google Play 64 位要求

Posted

技术标签:

【中文标题】React Native 0.61 版本中的 Google Play 64 位要求【英文标题】:Google Play 64-bit requirement in React Native Version 0.61 release 【发布时间】:2020-08-02 22:48:15 【问题描述】:

我以前用的是React Native的0.54版本,但是由于64位版本的谷歌有问题,不得不新建一个项目(这个版本我没有更新,但是我新建了一个版本)。

我目前正在使用 React Native 的 0.61.4 版本

在我得到 aab 输出并想在 Google Play 上发布它后,不幸的是我仍然遇到与以前相同的问题,并且出现以下错误

此版本不符合 Google Play 64 位要求

以下 APK 或 App Bundle 可用于 64 位设备,但它们只有 32 位本机代码:9.

在您的应用中包含 64 位和 32 位本机代码。使用 android App Bundle 发布格式自动确保每个设备架构只接收它需要的本机代码。这样可以避免增加应用的整体大小

我将gradle 代码放在这里以供指导

android/app/build.gradle

apply plugin: "com.android.application"

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
 *   entryFile: "index.android.js",
 *
 *   // https://facebook.github.io/react-native/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 = [
    entryFile: "index.js",
    enableHermes: true,  // 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 = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of javascriptCore.
 *
 * 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
 * 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 mirrored 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);

android 
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    

    defaultConfig 
        applicationId "com.....android"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 34
        versionName "3.0"
        multiDexEnabled true
    
    splits 
        abi 
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        
    
    signingConfigs 
        release 
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) 
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            
        
        debug 
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        
    
    buildTypes 
        debug 
            signingConfig signingConfigs.debug
        
        release 
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        
    
    // 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
            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 =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            

        
    


dependencies 
    implementation 'com.facebook.fresco:fresco:2.0.0'
    implementation 'com.facebook.fresco:animated-gif:2.0.0'
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    //https://github.com/kmagiera/react-native-screens
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'


    //https://github.com/react-native-community/react-native-maps/blob/master/docs/installation.md
    implementation(project(':react-native-maps'))
       exclude group: 'com.google.android.gms', module: 'play-services-base'
       exclude group: 'com.google.android.gms', module: 'play-services-maps'
    
    implementation 'com.google.android.gms:play-services-base:+'
    implementation 'com.google.android.gms:play-services-maps:+'

    if (enableHermes) 
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
     else 
        implementation jscFlavor
    


// 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.compile
    into 'libs'


apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)


// FIREBASE SDKs => https://invertase.io/oss/react-native-firebase/quick-start/android-firebase-credentials
apply plugin: 'com.google.gms.google-services'

android/gradle.properties

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

android.useAndroidX=true
android.enableJetifier=true


MYAPP_UPLOAD_STORE_FILE=key.jks
MYAPP_UPLOAD_KEY_ALIAS=MY_KEY_ALIAS
MYAPP_UPLOAD_STORE_PASSWORD=******
MYAPP_UPLOAD_KEY_PASSWORD=*****

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript 
    ext 
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    
    repositories 
        google()
        jcenter()
    
    dependencies 
        classpath('com.android.tools.build:gradle:3.5.1')

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // FIREBASE SDKs => https://invertase.io/oss/react-native-firebase/quick-start/android-firebase-credentials
        classpath 'com.google.gms:google-services:4.2.0'
    


allprojects 
    repositories 
        mavenLocal()
        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")
        

        google()
        jcenter()
        maven  url 'https://jitpack.io' 
    


更新

我在终端中运行以下命令以获取 AAB 文件:

$ cd android
$ gradlew cleanBuildCache
$ gradlew clean
$ gradlew bundleRelease

运行上述命令后,我会收到如下输出:

此版本中使用了已弃用的 Gradle 功能,使其与 Gradle 6.0 不兼容。 使用“--warning-mode all”显示各个弃用警告。 见http....

在 5m 21s 内构建成功 336 个可操作的任务:336 个已执行

在 Google 控制台中上传后

这很奇怪????

【问题讨论】:

您确定可以将应用上传到 Play 管理中心吗?当您之前尝试上传但失败时,您是否从 Play 商店中删除了具有相同 versionCode 的旧 APK/ 包?您的配置和 APK 看起来不错。 @BenB 是的,我确信该应用会成功上传到 Google 控制台。我每次都会增加 versionCode,因为 Google Play 根本不允许与 versionCode 重复,即使它失败了。您能否对此进行更多解释(删除以前的版本)。非常感谢您的 cmets 它不允许重复的版本代码,但您可以从工件库中删除应用程序。找到这个有帮助的指南:***.com/questions/45822460/… 我认为你不能删除它们,它们已经发布给用户。无论如何,这就是为什么您无法上传应用程序的相同版本代码的原因。现在你可以。但这并不能解决问题,但还是尝试重新上传。 您必须停用仍可用于您的发行版的先前版本。检查"Prepare & roll out releases > Step 2: Prepare your app's release > Android App Bundles and APKs to deactivate"。 【参考方案1】:

生成的 App Bundle ABB 文件没有任何问题。问题是有一个较旧的活动版本不包含 64 位二进制文​​件,您必须停用它才能让 Google Play 处理新版本。

请查看"Prepare & roll out releases" 文档中的"Step 2: Prepare your app's release > Android App Bundles and APKs to deactivate",了解如何停用以前的 APK/Bundle 版本。

【讨论】:

以上是关于React Native 0.61 版本中的 Google Play 64 位要求的主要内容,如果未能解决你的问题,请参考以下文章

初始 react-native run-ios 时缺少 Podfile.lock

React-Native 另一个 VirtualizedList 支持的容器

returnKeyType = react native 中的“下一个”问题

react native中所遇到的问题

现有应用程序中的 React Native 更新版本

在 Expo Go 上加载 Expo React Native 时遇到问题