我已经创建了一个带有以下变量的Ionic 6.19.1应用程序。gradle文件和“ionic capacitor run android”命令可以完美运行,应用程序也可以完美运行:
ext {
minSdkVersion = 26
compileSdkVersion = 30
targetSdkVersion = 30
androidxActivityVersion = '1.2.0
androidxAppCompatVersion = '1.2.0
androidxCoordinatorLayoutVersion = '1.1.0
androidxCoreVersion = '1.3.2
androidxFragmentVersion = '1.3.0
junitVersion = '4.13.1
androidxJunitVersion = '1.1.2
androidxEspressoCoreVersion = '3.3.0
cordovaAndroidVersion = '7.0.0'
}
但如果我将compileSdkVersion = 30替换为compileSdkVersion = 26,则“ionic capacitor run android”命令会产生以下错误:
> Task :capacitor-app:compileDebugJavaWithJavac FAILED
[capacitor] /Users/christophe/Documents/Sources/sylva/sycub/node_modules/@capacitor/app/android/src/main/java/com/capacitorjs/plugins/app/AppPlugin.java:84: error: cannot find symbol
[capacitor] if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
[capacitor] ^
[capacitor] symbol: variable P
[capacitor] location: class VERSION_CODES
[capacitor] /Users/christophe/Documents/Sources/sylva/sycub/node_modules/@capacitor/app/android/src/main/java/com/capacitorjs/plugins/app/AppPlugin.java:85: error: cannot find symbol
[capacitor] data.put("build", Long.toString(pinfo.getLongVersionCode()));
[capacitor] ^
[capacitor] symbol: method getLongVersionCode()
[capacitor] location: variable pinfo of type PackageInfo
[capacitor] 2 errors
[capacitor]
[capacitor] FAILURE: Build failed with an exception.
[capacitor]
[capacitor] * What went wrong:
[capacitor] Execution failed for task ':capacitor-app:compileDebugJavaWithJavac'.
[capacitor] > Compilation failed; see the compiler error output for details.
[capacitor]
[capacitor] * Try:
[capacitor] > Run with --stacktrace option to get the stack trace.
[capacitor] > Run with --info or --debug option to get more log output.
[capacitor] > Run with --scan to get full insights.
[capacitor]
[capacitor] * Get more help at https://help.gradle.org
[capacitor]
[capacitor] Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
[capacitor]
[capacitor] You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
[capacitor]
[capacitor] See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
[capacitor] 131 actionable tasks: 36 executed, 95 up-to-date
[capacitor]
[capacitor] BUILD FAILED in 1s
[capacitor]
[ERROR] An error occurred while running subprocess capacitor.
Java版本为“17”2021年9月14日LTS
Gradle已在Android Studio中更新
预先感谢你帮助
1条答案
按热度按时间thigvfpy1#
compileSdkVersion
是用于编译您的应用的SDK版本。如果您使用compileSdkVersion
26,则您使用的是针对Android 8(Android O)发布的SDK,因此它无法理解VERSION_CODES.P
的含义,因为Android P是在Android O之后发布的,Android O SDK上不存在VERSION_CODES.P
。您不应该使用
compileSdkVersion
26,compileSdkVersion
是可配置的,因此您可以在需要时使用较新的版本,但决不能使用较旧的版本。不知道你为什么要这样做,但谷歌将要求在8月使用SDK 32的新应用程序。