I update my cordova environment to Cordova Android 7 and got following error when 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)
And I added following parameter but same result.
$ cordova build android --device --verbose -- --gradleArg=-PcdvCompileSdkVersion=26
Does anyone know solution or workaround?
Generally, this method is used to indicate a method is called at an illegal or inappropriate time. Example: After starting a thread we are not allowed to restart the same thread once again otherwise we will get Runtime Exception saying IllegalStateException.
You are using android support library of 27.+ so you will have to give sdk version 27 as compileSdkVersion and targetSdkVersion otherwise your project does not know for which platform your project should be built. These parameter should be given in android directory like this in build.gradle (app):
Whether the exception is checked or unchecked every exception occurs at run time only if there is no chance of occurring any exception at compile time. IllegalStateException is the child class of RuntimeException and hence it is an unchecked exception.
This exception is rise explicitly by programmer or by the API developer to indicate that a method has been invoked at the wrong time. Generally, this method is used to indicate a method is called at an illegal or inappropriate time.
By running following command
ionic cordova build android --prod --no-build
I had suddenly the same issue:
java.lang.IllegalStateException: compileSdkVersion is not specified.
Maybe your issue is different, but you should be able to track your issue down like I describe now.
If you read further, there is more information:
FAILURE: Build failed with an exception.
* Where: Script '/***/platforms/android/CordovaLib/cordova.gradle' line: 132
Which is following function:
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))
}
I added a println and want to see which one crashes. And the output was (running above command to build android):
Crashing name: versionCode
Okay, I have in my config.xml
following set: android-versionCode="0.0.1"
So what's going on? The RegExp does not match the pattern anymore.
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));
And indeed the cordova manual page states it should be the following way:
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"
Hopefully this will help some guys since right now this issue was viewed 3000+ times.
I was getting the same error as yours while using
cordova run android
I solved the problem by downgrading my android platform in project using
cordova platform remove android
then
cordova platform add android@6
for me 6 worked well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With