我正在使用 Android Studio 开发一个项目,但我对 Android Studio 一无所知。 几个小时都解决不了gradle sync error。我的build.gradle是这样的:(不是错的,是app build.gradle)
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId 'com.kofax.sdk.samples.easysnap'
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName '1.0'
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
buildTypes {
release
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
lintOptions {
abortOnError false
}
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
def sdkRef
project.getRootProject().allprojects.each { proj ->
if (proj.name.toLowerCase().equals('sdk')) {
sdkRef = proj;
return true;
}
}
if (sdkRef) {
println "SDK present in project; using project reference as dependency"
compile sdkRef
} else {
println "SDK is not present in project; dependency reference"
repositories {
flatDir { dirs 'libs' }
}
compile (name: 'sdk-release', ext: 'aar')
}
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
}
我试图清理项目,但这不是关于它,是关于插件或丢失的文件或库? 我一直收到此错误:
Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
Possible causes for this unexpected error include:
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
- Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
- The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
- Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
请帮忙...
最佳答案
如果您在 Android Studio 3.0 上工作。在项目 gradle 中将“2.0.0”更改为“3.0.0”:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
在你的 gradle-wrapper.properties 中:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
在你的应用程序中:“编译”成为“实现”:
dependencies {
implementation 'com.android.support:appcompat-v7:27.0.0'
}
你应该阅读:
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
关于Android Studio 3 gradle 同步问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46991467/