首页 > 解决方案 > Android skdversion 找不到参数的方法 defaultConfig

问题描述

我遇到了 sdktargetconfiguration 的问题,所以我尝试在 AndroidManifest 中插入一个名为 defaultConfig 的方法,但现在我收到以下错误,即使我已经删除了这些行:

Could not find method defaultConfig() for arguments 
[build_4h41pri48v2dqhyz77npiqav8$_run_closure5$_closure11@40201fb5] on task 
':desktop:afterEclipseImport' of type org.gradle.api.DefaultTask. 

机器人清单

src/build.gradle:

在此处输入图像描述

在此处输入图像描述

我不知道是否需要更多信息,我现在只是不知道是什么导致了问题。我目前正在使用配置桌面来运行项目。提前感谢您提供帮助的任何人。

android/build.gradle:
apply plugin: 'com.android.application'

android {
buildToolsVersion '28.0.3'
compileSdkVersion 27
sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
        jniLibs.srcDirs = ['libs']
    }

    }
  packagingOptions {
    exclude 'META-INF/robovm/ios/robovm.xml'
  }
   defaultConfig {
    applicationId "com.mygdx.game"
    minSdkVersion 9
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    }
   buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
  'proguard-rules.pro'
    }
   }
}


// called every time gradle gets executed, takes the native dependencies of
 // the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() { 
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/arm64-v8a/").mkdirs();
file("libs/x86_64/").mkdirs();
file("libs/x86/").mkdirs();

configurations.natives.files.each { jar ->
    def outputDir = null
    if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = 
 file("libs/arm64-v8a")
    if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = 
 file("libs/armeabi-v7a")        
    if(jar.name.endsWith("natives-armeabi.jar")) outputDir = 
 file("libs/armeabi")
    if(jar.name.endsWith("natives-x86_64.jar")) outputDir = 
 file("libs/x86_64")
    if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
    if(outputDir != null) {
        copy {
            from zipTree(jar)
            into outputDir
            include "*.so"
        }
    }
}
}

task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
if (localProperties.exists()) {
    Properties properties = new Properties()
    localProperties.withInputStream { instr ->
        properties.load(instr)
    }
    def sdkDir = properties.getProperty('sdk.dir')
    if (sdkDir) {
        path = sdkDir
    } else {
        path = "$System.env.ANDROID_HOME"
    }
} else {
    path = "$System.env.ANDROID_HOME"
}

def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 
 'com.mygdx.game/com.mygdx.game.AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitly, SpringSource Gradle 
 Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
    main {
        java.srcDirs "src", 'gen'
    }
}

jdt {
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
}

classpath {
    plusConfigurations += [ project.configurations.compile ]        
    containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'       
}

project {
    name = appName + "-android"
    natures 'com.android.ide.eclipse.adt.AndroidNature'
    buildCommands.clear();
    buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
    buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
    buildCommand "org.eclipse.jdt.core.javabuilder"
    buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}

 // sets up the Android Idea project, using the old Ant based build.
idea {
module {
    sourceDirs += file("src");
    scopes = [ COMPILE: [plus:[project.configurations.compile]]]        

    iml {
        withXml {
            def node = it.asNode()
            def builder = NodeBuilder.newInstance();
            builder.current = node;
            builder.component(name: "FacetManager") {
                facet(type: "android", name: "Android") {
                    configuration {
                        option(name: "UPDATE_PROPERTY_FILES", value:"true")
                    }
                }
            }
        }
    }
}
}

桌面/build.gradle:

apply plugin: "java"
sourceCompatibility = 1.6
sourceSets.main.java.srcDirs = [ "src/" ]

project.ext.mainClassName = "com.mygdx.game.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/assets");

task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}

task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}

task dist(type: Jar) {
from files(sourceSets.main.output.classesDir)
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);

manifest {
    attributes 'Main-Class': project.mainClassName
}
}

dist.dependsOn classes

eclipse {
project {
    name = appName + "-desktop"
    linkedResource name: 'assets', type: '2', location: 'PARENT-1- 
PROJECT_LOC/android/assets'
}
}

task afterEclipseImport(description: "Post processing after project 
generation", group: "IDE") {
doLast {
def classpath = new XmlParser().parse(file(".classpath"))
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
def writer = new FileWriter(file(".classpath"))
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace(true)
printer.print(classpath)
}
}

标签: android

解决方案


在所有文件中搜索错误消息“defaultConfig”中的字符串并匹配大小写。即使您删除了最初尝试的内容,也必须留下一些残留物/工件。如果这不起作用,那么我会尝试重新构建或手动清理您的输出并从头开始构建。我知道有时当我使用 Visual Studio 时,它不够聪明,无法构建已更改并在旧的输出文件上运行的东西。


推荐阅读