Android 添加Google Play服务后Gradle项目刷新失败

Android 添加Google Play服务后Gradle项目刷新失败,android,libgdx,android-gradle-plugin,Android,Libgdx,Android Gradle Plugin,因此,在我将Google Play服务添加到dependencies中后,Gradle无法同步,我得到:无法更改配置::android:compile”,在解决Play Services错误后 我在这两个问题中发现了唯一相似的东西:和,但这对我没有帮助。而且我有一切最新的,我还添加了ANDROID_HOME变量只是为了确保。但还是一样 我使用Android studio和libGDX,如果这两者之间有任何联系,并且存在问题的话 gradle(模块:android) android{ buildT

因此,在我将Google Play服务添加到dependencies中后,Gradle无法同步,我得到:无法更改配置::android:compile”,在解决Play Services错误后

我在这两个问题中发现了唯一相似的东西:和,但这对我没有帮助。而且我有一切最新的,我还添加了ANDROID_HOME变量只是为了确保。但还是一样

我使用Android studio和libGDX,如果这两者之间有任何联系,并且存在问题的话

gradle(模块:android)

android{
buildToolsVersion“23.0.0”
编译DK23版
源集{
主要{
manifest.src文件“AndroidManifest.xml”
java.srcDirs=['src']
aidl.srcDirs=['src']
renderscript.srcDirs=['src']
res.srcDirs=['res']
assets.srcDirs=['assets']
}
instrumentTest.setRoot('tests'))
}
}
//在CLI上编译时需要将JNI共享库添加到APK
tasks.withType(com.android.build.gradle.tasks.PackageApplication){pkgTask->
pkgTask.jniFolders=new HashSet()
pkgTask.jniFolders.add(新文件(projectDir,'libs'))
}
//每次执行gradle时调用,获取
//本地配置,并将它们提取到适当的libs/文件夹中
//所以他们被APK包围了。
任务copyAndroidNatives(){
文件(“libs/armeabi/”).mkdirs();
文件(“libs/armeabi-v7a/”).mkdirs();
文件(“libs/x86/”).mkdirs();
configurations.natives.files.each{jar->
def outputDir=null
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.jar”))outputDir=file(“libs/x86”)
if(outputDir!=null){
抄袭{
来自zipTree(罐子)
输入输出目录
包括“*.so”
}
}
}
}
任务运行(类型:Exec){
def路径
def localProperties=project.file(“../local.properties”)
if(localProperties.exists()){
属性=新属性()
localProperties.withInputStream{instr->
属性。加载(instr)
}
def sdkDir=properties.getProperty('sdk.dir')
中频(sdkDir){
path=sdkDir
}否则{
path=“$System.env.ANDROID\u HOME”
}
}否则{
path=“$System.env.ANDROID\u HOME”
}
def adb=路径+“/平台工具/adb”
命令行“$adb”、“shell”、“am”、“start”、“n”、“path.to.project.android/path.to.project.android.AndroidLauncher”
}
//使用旧的基于Ant的构建设置Android Eclipse项目。
蚀{
//需要明确指定Java源代码集,SpringSource Gradle Eclipse插件
//忽略在classpath.file.withXml中添加的任何节点
源集{
主要{
java.srcDirs“src”,“gen”
}
}
jdt{
sourceCompatibility=1.6
targetCompatibility=1.6
}
类路径{
plusConfiguration+=project.configurations.compile
容器“com.android.ide.eclipse.adt.android_FRAMEWORK”、“com.android.ide.eclipse.adt.LIBRARIES”
}
计划{
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”
}
}
//使用旧的基于Ant的构建建立Android Idea项目。
意念{
模块{
sourceDirs+=文件(“src”);
范围=[COMPILE:[plus:[project.configurations.COMPILE]]
iml{
withXml{
def node=it.asNode()
def builder=NodeBuilder.newInstance();
builder.current=节点;
构件(名称:“FacetManager”){
刻面(类型:“安卓”,名称:“安卓”){
配置{
选项(名称:“更新属性文件”,值:“真”)
}
}
}
}
}
}
}
依赖关系{
编译'com.android.support:support-v13:23.0.0'
编译'com.google.android.gms:play services:7.8.0'
}

编辑:通过进一步的测试和尝试,我发现我不能在依赖项中添加任何内容。错误是相同的

我认为您的错误是在
android
块之外添加了
依赖项
。仔细看你的牙套。如果这仍然不能解决问题,那么在libgdx项目的顶级build.gradle文件中已经有一个android依赖项部分。试着把它们放在那里

给我们看看你的毕业文件我已经回答了这个问题,默认情况下是这样的。我把所有东西都放在安卓手镯里,但都是一样的。然后我在android gradle构建中有依赖项。如果我把核心的gradle依赖项放进去,它会说它找不到服务
android {
buildToolsVersion '23.0.0'
compileSdkVersion 23
sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    instrumentTest.setRoot('tests')
}
}
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
// 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/x86/").mkdirs();

configurations.natives.files.each { jar ->
    def outputDir = null
    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.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', 'path.to.project.android/path.to.project.android.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitely, 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")
                    }
                }
            }
        }
    }
}
}
dependencies {
    compile 'com.android.support:support-v13:23.0.0'
    compile 'com.google.android.gms:play-services:7.8.0'
}