【问题标题】:Android Studio gradle build cannot add dependencies on old build gradle fileAndroid Studio gradle build 无法在旧的 build gradle 文件上添加依赖项
【发布时间】:2015-08-13 20:15:22
【问题描述】:

我刚刚将旧的 gradle 项目从 ADT 导入到 Android Studio。所有 SDK、存储库 .. 已更新。我如何无法将依赖项添加到我的项目中。一直说找不到。如果我创建一个新项目,一切都很好。 这是我的 gradle 构建文件:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}
android {
    buildToolsVersion "19.1.0"
    compileSdkVersion 19

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        multiDexEnabled true
    }
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize '2g'
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
    }
    compileOptions {
        encoding "UTF-8"
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:support-v4:22.0.0'
    compile project(':core')
    compile 'org.slf4j:slf4j-android:1.7.7'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/App42MultiPlayerGamingSDK.jar')
    compile files('libs/google-play-services.jar')
    compile project(':facebook')
    //compile('com.android.support:appcompat-v7:21.0.3')
}
// 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', 'jangkoo.game.shadowfiend.android/jangkoo.game.shadowfiend.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")
                        }
                    }
                }
            }
        }
    }
}

我已经搜索了几天,但我找不到如何使用。 谁能告诉我我的 gradle 文件哪里出了问题?它来自 libGdx 构建。 对此有任何解决方案吗?我可以添加 jar 文件,但不能添加那些 google 库。

【问题讨论】:

  • 无法添加任何依赖项?确切的错误信息是什么?
  • 错误:找不到任何与 com.google.android.gms:play-services:+ 匹配的版本。在以下位置搜索:repo1.maven.org/maven2/com/google/android/gms/play-services/… ......
  • 您是否尝试过指定版本:compile 'com.google.android.gms:play-services:7.5.0',详见此处developers.google.com/android/guides/setup
  • 是的,一样。我尝试了新模块一切都很好,只是有了这个配置,不知道出了什么问题。它由 libgdx 生成。

标签: java android eclipse android-studio android-gradle-plugin


【解决方案1】:

我通过每晚构建 Libgdx、创建一个新项目并从旧项目复制源代码解决了我的问题。然后通过 Android Studio 导入 Android 库。我认为这是因为新的 Gradle 版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-08
    • 2021-07-10
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多