简体   繁体   中英

Gradle fails to sync after upgrading to Cordova Android 8.0

I just upgraded from cordova 7.1.4 to cordova 8.0.0. The build is successful on WebStorm, but the apk delivered can not be installed and when I open it in Android Studio gradle fails to sync with the following errors: “

The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.

    Open Manifest File

Move minSdkVersion to build file and sync project

”.

I can fix these errors on Android Studio but I need that WebStorm to deliver a valid apk. I added <preference name=”android-minSdkVersion” value=”19" /> to config.xml but it is not read from there. On Cordova 8.0.0 changes is mentioned “ Use custom Gradle properties to read minSdkVersion value from config.xml "but I don't understand what this means….I read on an article that an after_prepare hook script whould be the best solution.

Any idea how this script should look like? Any idea is welcome.

PS: I know the Cordova 9.0.0 fixed this problem, it reads minSdkVersion from config.xml file, but I need to fix this on Cordova 8.0.0

Check out this plugin

   <!-- These preferences are actually available in Cordova by default although not currently documented -->
<custom-preference name="android-minSdkVersion" value="10" />
<custom-preference name="android-maxSdkVersion" value="22" />
<custom-preference name="android-targetSdkVersion" value="21" />

<!-- Or you can use a custom-config-file element for them -->
<custom-config-file target="AndroidManifest.xml" parent="/*">
    <uses-sdk android:maxSdkVersion="22" android:minSdkVersion="10" android:targetSdkVersion="21" />
</custom-config-file>

If this fails, then you have this option

build-extras.gradle with the following content:

allprojects { project.ext { defaultMinSdkVersion=21 } }

copy this file in the platforms/android folder with a before_build hook and it does the job.

Or this

changing lines in file: platforms/android/gradle.properties

org.gradle.daemon=true org.gradle.jvmargs=-Xmx2048m android.useDeprecatedNdk=true cdvMinSdkVersion=21

to

org.gradle.daemon=true org.gradle.jvmargs=-Xmx2048m android.useDeprecatedNdk=true cdvMinSdkVersion=19

reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM