【问题标题】:Opening ported android project in Android Studio gives error在 Android Studio 中打开移植的 android 项目会出错
【发布时间】:2014-12-17 19:27:01
【问题描述】:

我正在尝试在 Android Studio 中打开移植的 Android 应用程序,但在尝试同步 gradle 时不断收到以下错误:Error:(1, 0) Plugin with id 'android' not found.。我看过很多关于这个问题的帖子,但没有一个解决方案对我有帮助。这是我的 gradle 文件:

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:appcompat-v7:21.+'
    compile 'com.google.android.gms:play-services:6.5.+'
    compile 'com.getbase:floatingactionbutton:1.3.0'
}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')

    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/... which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
}
}

如果我做错了什么或者您需要更多信息,请告诉我。你能为我指出正确的方向吗?提前谢谢你。

编辑

我已经实施了该问题的答案并得到了以下结果。请重新考虑

Error:Gradle version 1.10 is required. Current version is 2.2.1. If using the gradle wrapper, try editing the distributionUrl in C:\Users\Gerhardt\git\captis\gradle\wrapper\gradle-wrapper.properties to gradle-1.10-all.zip.

Please fix the project's Gradle settings.
<a href="openGradleSettings">Gradle settings</a>

所以我指向了 2.2.1 版本并得到了这个:

Error:Could not find com.android.tools.build:gradle:2.2.1.
Searched in the following locations:
    file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
    file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
Required by:
    :captis:unspecified

我不知道该怎么办。请指教?

【问题讨论】:

  • @Scott,我也有同样的问题。谷歌正在强迫我们迁移。那没问题。 AS很酷。但是随后您将其标记为 dup.... 但是 dup 链接并不能解决问题。 Surly这是一个错误吗?斯科特有什么想法吗?非常感谢您的意见。
  • 在 SO 上提出与之前提出的问题类似的问题时,最好详细说明。仅仅说“没有一个解决方案对我有帮助”通常不会帮助回答者理解为什么他们没有工作以及你的案例有何不同。
  • arggg...好点!现在感觉很傻。感谢您在下面的回答。

标签: android-studio


【解决方案1】:

这是Error:(1, 0) Plugin with id 'android' not found 的副本,但其代码的盲目复制粘贴会导致一些问题。

该问题建议您在构建脚本中放置带有repositoriesbuildscript 块,但由于答案引用了Android Studio 的早期版本,因此它具有较旧版本的Android Gradle 插件,不幸的是Android Studio发生这种情况时会给您一个无用且不正确的错误消息。这样做,注意classpath 语句中的较新版本。实际上,我假设您运行的是 Studio 1.0 或更高版本;如果您仍在运行测试版,您可能需要四处寻找正确的版本号:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

【讨论】:

  • 感谢您的回答! (并且不重复)。只需要添加一个导致错误的库就可以了
猜你喜欢
  • 2015-06-01
  • 1970-01-01
  • 2019-05-16
  • 1970-01-01
  • 2016-10-15
  • 2017-04-04
  • 2017-07-23
  • 2013-10-20
  • 2020-07-08
相关资源
最近更新 更多