我正在尝试在 Android studio 中打开移植的 Android 应用程序,当我尝试同步 gradle 时,我不断收到以下错误:错误:(1, 0) 未找到 id 为“android”的插件。
.我看过很多关于这个问题的帖子,但没有一个解决方案对我有帮助。这是我的 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
我不知道该怎么办。请告诉我?
最佳答案
这是 Error:(1, 0) Plugin with id 'android' not found 的重复项,但是盲目复制粘贴其代码会导致一些问题。
该问题建议您在构建脚本中放置一个带有 repositories
的 buildscript
block ,但由于答案引用了 Android Studio 的早期版本,因此它具有较旧的版本Android Gradle 插件的问题,不幸的是,当发生这种情况时,Android Studio 会给您一条无用且不正确的错误消息。执行此操作,注意 classpath
语句中的较新版本。实际上,我假设您运行的是 Studio 1.0 或更高版本;如果您仍在运行测试版,您可能需要四处寻找正确的版本号:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
关于android-studio - 在 Android Studio 中打开移植的 android 项目出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27533296/