【问题标题】:Gradle fails to sync after upgrading to Cordova Android 8.0升级到 Cordova Android 8.0 后 Gradle 无法同步
【发布时间】:2019-07-26 11:55:48
【问题描述】:

我刚刚从科尔多瓦 7.1.4 升级到科尔多瓦 8.0.0。在 WebStorm 上构建成功,但是无法安装交付的 apk,当我在 Android Studio 中打开它时 gradle 无法同步并出现以下错误:“

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

”。

我可以在 Android Studio 上修复这些错误,但我需要 WebStorm 来提供有效的 apk。 我在 config.xml 中添加了 <preference name=”android-minSdkVersion” value=”19" />,但没有从那里读取。 在Cordova 8.0.0 上提到更改“使用自定义Gradle 属性从config.xml 读取minSdkVersion 值”但我不明白这是什么意思……我在一篇文章中读到after_prepare 钩子脚本应该是最好的解决办法。

知道这个脚本应该是什么样子吗? 欢迎任何想法。

PS:我知道Cordova 9.0.0 解决了这个问题,它从 config.xml 文件中读取minSdkVersion,但我需要在Cordova 8.0.0 上解决这个问题

【问题讨论】:

    标签: android cordova gradle android-min-sdk


    【解决方案1】:

    查看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>
    

    如果失败,那么你有这个选项

    build-extras.gradle 包含以下内容:

    所有项目 { project.ext { defaultMinSdkVersion=21 } }

    将此文件复制到带有 before_build 的platforms/android 文件夹中 钩子,它完成了这项工作。

    或者这个

    更改文件中的行: 平台/android/gradle.properties

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

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

    reference

    【讨论】:

    • 我尝试了所有这些解决方案,但都不起作用。我不明白为什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 2018-07-24
    相关资源
    最近更新 更多