Cordova:java.lang.IllegalStateException:未指定compileSdkVersion。

时间:2018-03-07 10:56:59

标签: android cordova

我将我的cordova环境更新为Cordova Android 7,并在cordova build android --device --verbose时出现以下错误。

Command finished with error code 0: /usr/libexec/java_home
ANDROID_HOME=/Users/kano/Library/Android/sdk 
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home studio Subproject Path: CordovaLib Subproject Path: app Running command: /Users/kano/git_repositories/ncdc/KuiManagementSystem/app/platforms/android/gradlew cdvBuildDebug -b /Users/kano/git_repositories/ncdc/KuiManagementSystem/app/platforms/android/build.gradle
-Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true 
publishNonDefault is deprecated and has no effect anymore. 
All variants are now published. Failed to notify ProjectEvaluationListener.afterEvaluate(), 
but primary configuration failure takes precedence. 
java.lang.IllegalStateException: compileSdkVersion is not specified.
at com.google.common.base.Preconditions.checkState(Preconditions.java:456)
at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:590)
at com.android.build.gradle.BasePlugin.lambda$null$3(BasePlugin.java:555)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
at com.android.build.gradle.BasePlugin.lambda$createTasks$4(BasePlugin.java:551)
at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:91)

我添加了以下参数但结果相同。

$ cordova build android --device --verbose -- --gradleArg=-PcdvCompileSdkVersion=26

有谁知道解决方案或解决方法?

2 个答案:

答案 0 :(得分:2)

我在使用时遇到与您相同的错误

cordova run android

我通过使用以下项目将我的android平台降级来解决该问题

cordova platform remove android

然后

cordova platform add android@6

对我来说6很好

答案 1 :(得分:0)

通过运行以下命令

ionic cordova build android --prod --no-build

我突然遇到了同样的问题:

java.lang.IllegalStateException: compileSdkVersion is not specified.

也许您的问题有所不同,但是您应该能够像我现在描述的那样跟踪问题。


如果您进一步阅读,还有更多信息:

FAILURE: Build failed with an exception.

* Where: Script '/***/platforms/android/CordovaLib/cordova.gradle' line: 132

具有以下功能:

def doExtractIntFromManifest(name) {
    def manifestFile = file(android.sourceSets.main.manifest.srcFile)
    def pattern = Pattern.compile(name + "=\"(\\d+)\"")
    def matcher = pattern.matcher(manifestFile.getText())
    matcher.find()
    println('Crashing name: ' + name) // <-- I added this line
    return new BigInteger(matcher.group(1))
}

我添加了一个 println ,并希望查看哪一个崩溃了。 输出为(运行上述命令以构建android):

Crashing name: versionCode

好的,我的config.xml中包含以下内容:android-versionCode="0.0.1"

那是怎么回事? RegExp与模式不再匹配。

var a = 'android-versionCode="1"';
var a1 = 'android-versionCode="1.0.0"';
var b = new RegExp('versionCode' + "=\"(\\d+)\"");

console.log('With Version as 1:', b.exec(a));
console.log('With Version as 1.0.0:', b.exec(a1));

事实上,cordova手册页指出应采用以下方式:

https://cordova.apache.org/docs/de/latest/config_ref/

<widget id="io.cordova.hellocordova"
  version="0.0.1"
  android-versionCode="7"
  ios-CFBundleVersion="3.3.3">

versionCode = PATCH + MINOR * 100 + MAJOR * 10000
CFBundleVersion = "MAJOR.MINOR.PATCH"

希望这对某些人有所帮助,因为该问题目前已被查看3000多次。