2017-10-28 138 views
0

我正在与Android Studio进行项目工作,但我不知道Android Studio .. 无法解决几个小时的同步错误。我的build.gradle是这样的:(不是错了,它的应用的build.gradle)Android Studio 3 gradle sync问题

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' 
} 

我试图清理项目它不是关于它,是关于插件或失踪filesor库? 我不断收到此错误:

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:

  • 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.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

请帮助...

+0

如果您使用的Android 3.0的工作室则gradle这个插件版本是3.0.0( 'com.android.tools.build:gradle:3.0.0' )和分配中nUrl是\ https \://services.gradle.org/distributions/gradle-4.1-all.zip –

回答

1

如果您在Android 3.0工作室工作。更改 “2.0.0” 改为 “3.0.0” 在你的gradle项目:

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 

在您的应用程序gradle这个: “编译” 变成了“实施“:

dependencies { 
    implementation 'com.android.support:appcompat-v7:27.0.0' 
} 

你应该阅读:

https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

+0

完成这些解决了错误,非常感谢!但现在我得到这个:_Error:无法解决:: sdk-release:_ 它在项目 - >库。为什么不能解决? –

+0

可能更改编译(名称:'sdk-release',ext:'aar')到实现(名称:'sdk-release',ext:'aar') 请看看这个:https://developer.android .COM /工作室/编译/ gradle这个-插件-3-0-0-migration.html#local_jars – sokarcreative

2

Android插件3.0.0需要Gradle版本4.1或更高版本。如果您使用Android Studio 3.0或更高版本打开现有项目,请按照提示自动将现有项目更新为兼容版本的Gradle。

要手动更新摇篮,在gradle-wrapper.properties编辑URL以下几点:distributionUrl=\https\://services.gradle.org/distributions/gradle-4.1-all.zip

,包括Maven的回购和在项目级别的build.gradle更改插件版本文件如下:

buildscript { 

     repositories { 
      ... 
      // You need to add the following repository to download the 
      // new plugin. 
      google() 
     } 

     dependencies { 
      classpath 'com.android.tools.build:gradle:3.0.0' 
     } 
    }