【问题标题】:Using Flavors to create different apk's using React Native and Android使用 Flavor 使用 React Native 和 Android 创建不同的 apk
【发布时间】:2017-01-24 19:54:49
【问题描述】:

我正在尝试在使用 React Native 编写的 Android 应用中创建不同的 APK,但在运行 .gradlew assembleRelease 或任何其他组合时出现以下错误:

Could not find method applicationIdSuffix() for arguments [.free] on ProductFlavor_Decorated{name=free, dimension=null, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptNdkModeEnabled=null, versionCode=null, versionName=null, applicationId=null, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}}.

当我删除 productFlavors 时,构建过程正常。

build.gradle 文件如下所示:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 27
        versionName "3.3.1"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    productFlavors {
        free {
            applicationIdSuffix ".free"
        }
        pro {
            applicationIdSuffix ".pro"
        }
    }
    ...
}

gradle-wrapper.properties的内容如下:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

不知道出了什么问题。知道我缺少什么吗?此外,我使用Webstorm 作为 IDE,因为我正在开发一个 ReactNative 项目并且我主要处理 JS 代码,如果我使用 AndroidStudio 工作,事情会变得更容易,尤其是关于 android 配置的事情。

谢谢

【问题讨论】:

  • 如果您运行gradlew tasks,您应该会看到所有可用的任务。通常你会在buildTypes 下有releasedebug 条目,然后运行类似assembleFreeRelease 的东西
  • 即使gradlew tasks 命令在添加productFlavors 后也会出现同样的错误
  • developer.android.com/studio/releases/… 据此,对于 v2.14.1,它表示“您现在可以为产品风味指定 versionNameSuffix 和 applicationIdSuffix。(问题 59614)”。您可以尝试更新包装器中的 gradle 吗?

标签: android gradle react-native android-productflavors android-build-flavors


【解决方案1】:

将 resValue 行添加到您的“免费”风格中

productFlavors {
        free {
            applicationIdSuffix ".free"
            resValue "string", "build_config_package", "com.your_package" // the package of your Android app
        }
        pro {
            applicationIdSuffix ".pro"
        }
    }
    ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 2016-11-06
    相关资源
    最近更新 更多