【发布时间】: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下有release和debug条目,然后运行类似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