2017-10-28 135 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' 
     } 
    }