Ionic:未指定compileSdkVersion - 找不到leftShift()方法。

3

我刚刚开始使用Ionic 4开发我的应用程序。目前为止,在启动项目时,我从未对原始代码进行任何修改(包括侧边菜单)。 在遇到其他许多错误后,我现在遇到了一个不知道如何解决的问题。 当我尝试执行以下命令时会出现该错误:

ionic cordova build android

    FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'D:\workspace\iganalytics\app\platforms\android\app\build.gradle' line: 148

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method leftShift() for arguments [build_8ka4my3njl1nfn72j8pdlyfze$_run_closure6@5b9f348] on task ':app:cdvPrintProps' of type org.gradle.api.DefaultTask.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
cmd: Command failed with exit code 1 Error output:
FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'D:\workspace\iganalytics\app\platforms\android\app\build.gradle' line: 148

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method leftShift() for arguments [build_8ka4my3njl1nfn72j8pdlyfze$_run_closure6@5b9f348] on task ':app:cdvPrintProps' of type org.gradle.api.DefaultTask.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
[ERROR] An error occurred while running subprocess cordova.

        cordova build android exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

我在config.xml中添加了这行代码:
<preference name="android-targetSdkVersion" value="28" />

未能成功。

build.gradle文件的第148行起始位置为:

task cdvPrintProps << {
    println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
    println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
    println('cdvVersionCode=' + cdvVersionCode)
    println('cdvVersionCodeForceAbiDigit=' + cdvVersionCodeForceAbiDigit)
    println('cdvMinSdkVersion=' + cdvMinSdkVersion)
    println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
    println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
    println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
    println('cdvBuildArch=' + cdvBuildArch)
    println('computedVersionCode=' + android.defaultConfig.versionCode)
    android.productFlavors.each { flavor ->
        println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
    }
}

你在Android Studio中安装了Android SDK版本28吗? - Anandh Sp
你使用的 cordova-android 和 gradle 版本是什么? - Jay Ordway
@AnandhSp 是的,我有。 - Splinteer
@JayOrdway Android 7和gradle 5.2.1 - Splinteer
3个回答

4
通过添加平台android@8而不是只安装版本7,我成功使它运行。

3

我遇到了同样的问题。解决方案是升级到android@8。感谢@Splinteer。

以下是更详细的操作步骤:

列出您的平台:

ionic cordova platform list

使用以下步骤移除Android:

ionic cordova platform rm android

添加 Android@8:

ionic cordova platform add android@8

2
昨天我遇到了类似的问题,并通过在config.xml中添加<preference name="android-targetSdkVersion" value="22" />来解决。翻译成中文为:昨天我也遇到了类似的问题,解决方法是在config.xml文件中添加<preference name="android-targetSdkVersion" value="22" />

如果Play Store的要求是26,那么这可能不是一个好的长期解决方案:https://developer.android.com/distribute/best-practices/develop/target-sdk - Chris J

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接