在以下任何来源中均未找到插件 [id:'com.android.application',版本:'8.5.0']:

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

我正在使用 godot 4.3 beta,当我导出到 android apk 时出现这个问题

 editor/export/editor_export_platform.h:182 - Export: Building of Android project failed, check output for the error:
  
  
  FAILURE: Build failed with an exception.
  
  * Where:
  Build file 'E:\Ahmed\godot\projects\‏‏ADMOB4.3\android\build\build.gradle' line: ?
  
  * What went wrong:
  Plugin [id: 'com.android.application', version: '8.5.0'] was not found in any of the following sources:
  
  - Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
  - Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:8.5.0')
    Searched in the following repositories:
      Google
      MavenRepo
      Gradle Central Plugin Repository
      maven(https://plugins.gradle.org/m2/)
  
  * 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 2s

这是

build.gradle
的完整代码:

// Gradle build config for Godot Engine's Android port.
plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

apply from: 'config.gradle'

allprojects {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
        maven { url "https://plugins.gradle.org/m2/" }

        // Godot user plugins custom maven repos
        String[] mavenRepos = getGodotPluginsMavenRepos()
        if (mavenRepos != null && mavenRepos.size() > 0) {
            for (String repoUrl : mavenRepos) {
                maven {
                    url repoUrl
                }
            }
        }
    }
}

configurations {
    // Initializes a placeholder for the devImplementation dependency configuration.
    devImplementation {}
}

dependencies {
    implementation "androidx.fragment:fragment:$versions.fragmentVersion"

    if (rootProject.findProject(":lib")) {
        implementation project(":lib")
    } else if (rootProject.findProject(":godot:lib")) {
        implementation project(":godot:lib")
    } else {
        // Godot gradle build mode. In this scenario this project is the only one around and the Godot
        // library is available through the pre-generated godot-lib.*.aar android archive files.
        debugImplementation fileTree(dir: 'libs/debug', include: ['*.jar', '*.aar'])
        devImplementation fileTree(dir: 'libs/dev', include: ['*.jar', '*.aar'])
        releaseImplementation fileTree(dir: 'libs/release', include: ['*.jar', '*.aar'])
    }

    // Godot user plugins remote dependencies
    String[] remoteDeps = getGodotPluginsRemoteBinaries()
    if (remoteDeps != null && remoteDeps.size() > 0) {
        for (String dep : remoteDeps) {
            implementation dep
        }
    }

    // Godot user plugins local dependencies
    String[] pluginsBinaries = getGodotPluginsLocalBinaries()
    if (pluginsBinaries != null && pluginsBinaries.size() > 0) {
        implementation files(pluginsBinaries)
    }
}

android {
    compileSdkVersion versions.compileSdk
    buildToolsVersion versions.buildTools
    ndkVersion versions.ndkVersion

    compileOptions {
        sourceCompatibility versions.javaVersion
        targetCompatibility versions.javaVersion
    }

    kotlinOptions {
        jvmTarget = versions.javaVersion
    }

    assetPacks = [":assetPacks:installTime"]

    namespace = 'com.godot.game'

    defaultConfig {
        // The default ignore pattern for the 'assets' directory includes hidden files and directories which are used by Godot projects.
        aaptOptions {
            ignoreAssetsPattern "!.svn:!.git:!.gitignore:!.ds_store:!*.scc:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"
        }

        ndk {
            String[] export_abi_list = getExportEnabledABIs()
            abiFilters export_abi_list
        }

        manifestPlaceholders = [godotEditorVersion: getGodotEditorVersion()]

        // Feel free to modify the application id to your own.
        applicationId getExportPackageName()
        versionCode getExportVersionCode()
        versionName getExportVersionName()
        minSdkVersion getExportMinSdkVersion()
        targetSdkVersion getExportTargetSdkVersion()

        missingDimensionStrategy 'products', 'template'
    }

    lintOptions {
        abortOnError false
        disable 'MissingTranslation', 'UnusedResources'
    }

    ndkVersion versions.ndkVersion

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'

        // 'doNotStrip' is enabled for development within Android Studio
        if (shouldNotStrip()) {
            doNotStrip '**/*.so'
        }

        jniLibs {
            // Setting this to true causes AGP to package compressed native libraries when building the app
            // For more background, see:
            // - https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs
            // - https://stackoverflow.com/a/44704840
            useLegacyPackaging shouldUseLegacyPackaging()
        }
    }

    signingConfigs {
        debug {
            if (hasCustomDebugKeystore()) {
                storeFile new File(getDebugKeystoreFile())
                storePassword getDebugKeystorePassword()
                keyAlias getDebugKeyAlias()
                keyPassword getDebugKeystorePassword()
            }
        }

        release {
            File keystoreFile = new File(getReleaseKeystoreFile())
            if (keystoreFile.isFile()) {
                storeFile keystoreFile
                storePassword getReleaseKeystorePassword()
                keyAlias getReleaseKeyAlias()
                keyPassword getReleaseKeystorePassword()
            }
        }
    }

    buildTypes {

        debug {
            // Signing and zip-aligning are skipped for prebuilt builds, but
            // performed for Godot gradle builds.
            zipAlignEnabled shouldZipAlign()
            if (shouldSign()) {
                signingConfig signingConfigs.debug
            } else {
                signingConfig null
            }
        }

        dev {
            initWith debug
            // Signing and zip-aligning are skipped for prebuilt builds, but
            // performed for Godot gradle builds.
            zipAlignEnabled shouldZipAlign()
            if (shouldSign()) {
                signingConfig signingConfigs.debug
            } else {
                signingConfig null
            }
        }

        release {
            // Signing and zip-aligning are skipped for prebuilt builds, but
            // performed for Godot gradle builds.
            zipAlignEnabled shouldZipAlign()
            if (shouldSign()) {
                signingConfig signingConfigs.release
            } else {
                signingConfig null
            }
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
            aidl.srcDirs = ['aidl']
            assets.srcDirs = ['assets']
        }
        debug.jniLibs.srcDirs = ['libs/debug', 'libs/debug/vulkan_validation_layers']
        dev.jniLibs.srcDirs = ['libs/dev']
        release.jniLibs.srcDirs = ['libs/release']
    }

    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            output.outputFileName = "android_${variant.name}.apk"
        }
    }
}

task copyAndRenameDebugApk(type: Copy) {
    from "$buildDir/outputs/apk/debug/android_debug.apk"
    into getExportPath()
    rename "android_debug.apk", getExportFilename()
}

task copyAndRenameDevApk(type: Copy) {
    from "$buildDir/outputs/apk/dev/android_dev.apk"
    into getExportPath()
    rename "android_dev.apk", getExportFilename()
}

task copyAndRenameReleaseApk(type: Copy) {
    from "$buildDir/outputs/apk/release/android_release.apk"
    into getExportPath()
    rename "android_release.apk", getExportFilename()
}

task copyAndRenameDebugAab(type: Copy) {
    from "$buildDir/outputs/bundle/debug/build-debug.aab"
    into getExportPath()
    rename "build-debug.aab", getExportFilename()
}

task copyAndRenameDevAab(type: Copy) {
    from "$buildDir/outputs/bundle/dev/build-dev.aab"
    into getExportPath()
    rename "build-dev.aab", getExportFilename()
}

task copyAndRenameReleaseAab(type: Copy) {
    from "$buildDir/outputs/bundle/release/build-release.aab"
    into getExportPath()
    rename "build-release.aab", getExportFilename()
}

/**
 * Used to validate the version of the Java SDK used for the Godot gradle builds.
 */
task validateJavaVersion {
    if (JavaVersion.current() != versions.javaVersion) {
        throw new GradleException("Invalid Java version ${JavaVersion.current()}. Version ${versions.javaVersion} is the required Java version for Godot gradle builds.")
    }
}

/*
When they're scheduled to run, the copy*AARToAppModule tasks generate dependencies for the 'app'
module, so we're ensuring the ':app:preBuild' task is set to run after those tasks.
 */
if (rootProject.tasks.findByPath("copyDebugAARToAppModule") != null) {
    preBuild.mustRunAfter(rootProject.tasks.named("copyDebugAARToAppModule"))
}
if (rootProject.tasks.findByPath("copyDevAARToAppModule") != null) {
    preBuild.mustRunAfter(rootProject.tasks.named("copyDevAARToAppModule"))
}
if (rootProject.tasks.findByPath("copyReleaseAARToAppModule") != null) {
    preBuild.mustRunAfter(rootProject.tasks.named("copyReleaseAARToAppModule"))
}

config.gradle

ext.versions = [
    androidGradlePlugin: '8.5.0',
    compileSdk         : 34,
    // Also update 'platform/android/export/export_plugin.cpp#OPENGL_MIN_SDK_VERSION'
    minSdk             : 21,
    // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
    targetSdk          : 34,
    buildTools         : '34.0.0',
    kotlinVersion      : '1.9.20',
    fragmentVersion    : '1.6.2',
    nexusPublishVersion: '1.3.0',
    javaVersion        : JavaVersion.VERSION_21,
    // Also update 'platform/android/detect.py#get_ndk_version()' when this is updated.
    ndkVersion         : '23.2.8568313'

]

ext.getExportPackageName = { ->
    // Retrieve the app id from the project property set by the Godot build command.
    String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
    // Check if the app id is valid, otherwise use the default.
    if (appId == null || appId.isEmpty()) {
        appId = "com.godot.game"
    }
    return appId
}

ext.getExportVersionCode = { ->
    String versionCode = project.hasProperty("export_version_code") ? project.property("export_version_code") : ""
    if (versionCode == null || versionCode.isEmpty()) {
        versionCode = "1"
    }
    try {
        return Integer.parseInt(versionCode)
    } catch (NumberFormatException ignored) {
        return 1
    }
}

ext.getExportVersionName = { ->
    String versionName = project.hasProperty("export_version_name") ? project.property("export_version_name") : ""
    if (versionName == null || versionName.isEmpty()) {
        versionName = "1.0"
    }
    return versionName
}

ext.getExportMinSdkVersion = { ->
    String minSdkVersion = project.hasProperty("export_version_min_sdk") ? project.property("export_version_min_sdk") : ""
    if (minSdkVersion == null || minSdkVersion.isEmpty()) {
        minSdkVersion = "$versions.minSdk"
    }
    try {
        return Integer.parseInt(minSdkVersion)
    } catch (NumberFormatException ignored) {
        return versions.minSdk
    }
}

ext.getExportTargetSdkVersion = { ->
    String targetSdkVersion = project.hasProperty("export_version_target_sdk") ? project.property("export_version_target_sdk") : ""
    if (targetSdkVersion == null || targetSdkVersion.isEmpty()) {
        targetSdkVersion = "$versions.targetSdk"
    }
    try {
        return Integer.parseInt(targetSdkVersion)
    } catch (NumberFormatException ignored) {
        return versions.targetSdk
    }
}

ext.getGodotEditorVersion = { ->
    String editorVersion = project.hasProperty("godot_editor_version") ? project.property("godot_editor_version") : ""
    if (editorVersion == null || editorVersion.isEmpty()) {
        // Try the library version first
        editorVersion = getGodotLibraryVersionName()

        if (editorVersion.isEmpty()) {
            // Fallback value.
            editorVersion = "custom_build"
        }
    }
    return editorVersion
}

ext.getGodotLibraryVersionCode = { ->
    String versionName = ""
    int versionCode = 1
    (versionName, versionCode) = getGodotLibraryVersion()
    return versionCode
}

ext.getGodotLibraryVersionName = { ->
    String versionName = ""
    int versionCode = 1
    (versionName, versionCode) = getGodotLibraryVersion()
    return versionName
}

ext.generateGodotLibraryVersion = { List<String> requiredKeys ->
    // Attempt to read the version from the `version.py` file.
    String libraryVersionName = ""
    int libraryVersionCode = 0

    File versionFile = new File("../../../version.py")
    if (versionFile.isFile()) {
        def map = [:]

        List<String> lines = versionFile.readLines()
        for (String line in lines) {
            String[] keyValue = line.split("=")
            String key = keyValue[0].trim()
            String value = keyValue[1].trim().replaceAll("\"", "")

            if (requiredKeys.contains(key)) {
                if (!value.isEmpty()) {
                    map[key] = value
                }
                requiredKeys.remove(key)
            }
        }

        if (requiredKeys.empty) {
            libraryVersionName = map.values().join(".")
            try {
                if (map.containsKey("status")) {
                    int statusCode = 0
                    String statusValue = map["status"]
                    if (statusValue == null) {
                        statusCode = 0
                    } else if (statusValue.startsWith("dev")) {
                        statusCode = 1
                    } else if (statusValue.startsWith("alpha")) {
                        statusCode = 2
                    } else if (statusValue.startsWith("beta")) {
                        statusCode = 3
                    } else if (statusValue.startsWith("rc")) {
                        statusCode = 4
                    } else if (statusValue.startsWith("stable")) {
                        statusCode = 5
                    } else {
                        statusCode = 0
                    }

                    libraryVersionCode = statusCode
                }

                if (map.containsKey("patch")) {
                    libraryVersionCode += Integer.parseInt(map["patch"]) * 10
                }

                if (map.containsKey("minor")) {
                    libraryVersionCode += (Integer.parseInt(map["minor"]) * 1000)
                }

                if (map.containsKey("major")) {
                    libraryVersionCode += (Integer.parseInt(map["major"]) * 100000)
                }
            } catch (NumberFormatException ignore) {
                libraryVersionCode = 1
            }
        }
    }

    if (libraryVersionName.isEmpty()) {
        // Fallback value in case we're unable to read the file.
        libraryVersionName = "custom_build"
    }

    if (libraryVersionCode == 0) {
        libraryVersionCode = 1
    }

    return [libraryVersionName, libraryVersionCode]
}

ext.getGodotLibraryVersion = { ->
    List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
    return generateGodotLibraryVersion(requiredKeys)
}

ext.getGodotPublishVersion = { ->
    List<String> requiredKeys = ["major", "minor", "patch", "status"]
    String versionName = ""
    int versionCode = 1
    (versionName, versionCode) = generateGodotLibraryVersion(requiredKeys)
    if (!versionName.endsWith("stable")) {
        versionName += "-SNAPSHOT"
    }
    return versionName
}

final String VALUE_SEPARATOR_REGEX = "\\|"

// get the list of ABIs the project should be exported to
ext.getExportEnabledABIs = { ->
    String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : "";
    if (enabledABIs == null || enabledABIs.isEmpty()) {
        enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
    }
    Set<String> exportAbiFilter = [];
    for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
        if (!abi_name.trim().isEmpty()){
            exportAbiFilter.add(abi_name);
        }
    }
    return exportAbiFilter;
}

ext.getExportPath = {
    String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
    if (exportPath == null || exportPath.isEmpty()) {
        exportPath = "."
    }
    return exportPath
}

ext.getExportFilename = {
    String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
    if (exportFilename == null || exportFilename.isEmpty()) {
        exportFilename = "godot_android"
    }
    return exportFilename
}

/**
 * Parse the project properties for the 'plugins_maven_repos' property and return the list
 * of maven repos.
 */
ext.getGodotPluginsMavenRepos = { ->
    Set<String> mavenRepos = []

    // Retrieve the list of maven repos.
    if (project.hasProperty("plugins_maven_repos")) {
        String mavenReposProperty = project.property("plugins_maven_repos")
        if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
            for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
                mavenRepos += mavenRepoUrl.trim()
            }
        }
    }

    return mavenRepos
}

/**
 * Parse the project properties for the 'plugins_remote_binaries' property and return
 * it for inclusion in the build dependencies.
 */
ext.getGodotPluginsRemoteBinaries = { ->
    Set<String> remoteDeps = []

    // Retrieve the list of remote plugins binaries.
    if (project.hasProperty("plugins_remote_binaries")) {
        String remoteDepsList = project.property("plugins_remote_binaries")
        if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
            for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
                remoteDeps += dep.trim()
            }
        }
    }
    return remoteDeps
}

/**
 * Parse the project properties for the 'plugins_local_binaries' property and return
 * their binaries for inclusion in the build dependencies.
 */
ext.getGodotPluginsLocalBinaries = { ->
    Set<String> binDeps = []

    // Retrieve the list of local plugins binaries.
    if (project.hasProperty("plugins_local_binaries")) {
        String pluginsList = project.property("plugins_local_binaries")
        if (pluginsList != null && !pluginsList.trim().isEmpty()) {
            for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
                binDeps += plugin.trim()
            }
        }
    }

    return binDeps
}

ext.getDebugKeystoreFile = { ->
    String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
    if (keystoreFile == null || keystoreFile.isEmpty()) {
        keystoreFile = "."
    }
    return keystoreFile
}

ext.hasCustomDebugKeystore = { ->
    File keystoreFile = new File(getDebugKeystoreFile())
    return keystoreFile.isFile()
}

ext.getDebugKeystorePassword = { ->
    String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
    if (keystorePassword == null || keystorePassword.isEmpty()) {
        keystorePassword = "android"
    }
    return keystorePassword
}

ext.getDebugKeyAlias = { ->
    String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
    if (keyAlias == null || keyAlias.isEmpty()) {
        keyAlias = "androiddebugkey"
    }
    return keyAlias
}

ext.getReleaseKeystoreFile = { ->
    String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
    if (keystoreFile == null || keystoreFile.isEmpty()) {
        keystoreFile = "."
    }
    return keystoreFile
}

ext.getReleaseKeystorePassword = { ->
    String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
    return keystorePassword
}

ext.getReleaseKeyAlias = { ->
    String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
    return keyAlias
}

ext.isAndroidStudio = { ->
    def sysProps = System.getProperties()
    return sysProps != null && sysProps['idea.platform.prefix'] != null
}

ext.shouldZipAlign = { ->
    String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
    if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
        if (isAndroidStudio()) {
            zipAlignFlag = "true"
        } else {
            zipAlignFlag = "false"
        }
    }
    return Boolean.parseBoolean(zipAlignFlag)
}

ext.shouldSign = { ->
    String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
    if (signFlag == null || signFlag.isEmpty()) {
        if (isAndroidStudio()) {
            signFlag = "true"
        } else {
            signFlag = "false"
        }
    }
    return Boolean.parseBoolean(signFlag)
}

ext.shouldNotStrip = { ->
    return isAndroidStudio() || project.hasProperty("doNotStrip")
}

/**
 * Whether to use the legacy convention of compressing all .so files in the APK.
 *
 * For more background, see:
 * - https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs
 * - https://stackoverflow.com/a/44704840
 */
ext.shouldUseLegacyPackaging = { ->
    int minSdk = getExportMinSdkVersion()
    if (minSdk < 23) {
        // Enforce the default behavior for compatibility with device running api < 23
        return true
    }

    String legacyPackagingFlag = project.hasProperty("compress_native_libraries") ? project.property("compress_native_libraries") : ""
    if (legacyPackagingFlag != null && !legacyPackagingFlag.isEmpty()) {
        return Boolean.parseBoolean(legacyPackagingFlag)
    }

    // Default behavior for minSdk >= 23
    return false
}

我尝试用新的 Android 构建模板替换它来解决问题,但没有成功 我上网查了也没找到明确的答案

注意* 我的英语不好,所以你能用简单的语言解释一下你在说什么吗(我正在努力提高我的语言水平) 我该怎么办,因为这个问题已经困扰我两天了

gradle build.gradle godot gradle-plugin godot4
1个回答
0
投票

Android Gradle 插件还没有 8.5.0 版本。请参阅repo

尝试更换为最新稳定版本

androidGradlePlugin: '8.3.2'
© www.soinside.com 2019 - 2024. All rights reserved.