由于“无效源版本:17”,在 Android 中构建 Ionic React 应用程序时出错 - 我该如何解决它?

问题描述 投票:0回答:2

我正在尝试在 Android 中构建一个 Ionic React 应用程序,但没有成功。该应用程序在浏览器中运行得很好,但无法构建。我使用了以下步骤:

  1. 离子电容器构建
  2. npx 上限添加 android
  3. 离子电容器同步安卓
  4. 离子电容器开放android

现在项目无法正确构建 - Gradle 构建将运行,但它无法正常工作,因为它指出“原因:错误:无效源版本:17” 我尝试将 build.gradle 文件中的 java 版本更改为 16,但它仍然提示 17 相同的错误。

我还将capacitor.build.gradle修改为16,但仍然显示相同的错误。

这就是 build.gradle 文件现在的样子:

apply plugin: 'com.android.application'

android {
    namespace "ionic.io.starter"
    compileSdkVersion rootProject.ext.compileSdkVersion
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_16
        targetCompatibility JavaVersion.VERSION_16
    }
    defaultConfig {
        applicationId "ionic.io.starter"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        aaptOptions {
             // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
             // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
            ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    flatDir{
        dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
    implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
    implementation project(':capacitor-android')
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
    implementation project(':capacitor-cordova-android-plugins')
}

apply from: 'capacitor.build.gradle'

try {
    def servicesJSON = file('google-services.json')
    if (servicesJSON.text) {
        apply plugin: 'com.google.gms.google-services'
    }
} catch(Exception e) {
    logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
android react-native ionic-framework build.gradle capacitor
2个回答
1
投票

您使用的 Android Studio 版本是什么?我使用 Capacitor 遇到了类似的问题,这对我有帮助:https://capacitorjs.com/docs/updating/5-0

Capacitor 5 需要 Android Studio Flamingo | 2022.2.1 或更高版本,因为使用 Gradle 8,需要 Java JDK 17。Java 17 附带 Android Studio Flamingo。无需额外下载!

在更新到新版本的 Android Studio Flamingo 之前,我遇到了同样的错误。希望这也能帮助你。


0
投票

请尝试更改以下gradle文件中已安装的JAVA SDK版本,然后尝试构建,

< project > 安卓 p

© www.soinside.com 2019 - 2024. All rights reserved.