2017-02-14 115 views
1

我最近更新了我的JAVA版本到1.8版本,並且還製作了android studio更新和gradle插件更新。更新後我得到的編譯我的項目按照我的模塊(即Facebook的模塊)的build.gradle文件的一個錯誤:Android Studio更新 - 無法解析com.android.databinding

enter image description here

我的項目級的build.gradle看起來是這樣的:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.3.0-beta4' 
     classpath 'com.google.gms:google-services:2.0.0-alpha6' 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

此外還有一些符號未找到像無法解析符號'GradleScriptException'的錯誤,無法解析facebook模塊build.gradle文件中的'MavenDeployment'符號。 Facebook的buil.gradle的完整代碼:

apply plugin: 'com.android.library' 

repositories { 
    mavenCentral() 
} 

project.group = 'com.facebook.android' 

dependencies { 
    // Facbook Dependancies 
    testCompile 'com.android.support:appcompat-v7:23.0.1' 
    compile 'com.android.support:support-v4:23.0.1' 
    compile 'com.parse.bolts:bolts-android:1.2.1' 
    // Unit Tests 
    testCompile 'junit:junit:4.12' 
    testCompile 'org.robolectric:robolectric:3.0' 
    testCompile 'org.robolectric:shadows-support-v4:3.0' 
    def powerMockVersion = '1.6.1' 
    testCompile "org.powermock:powermock-module-junit4:$powerMockVersion" testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion" testCompile "org.powermock:powermock-classloading-xstream:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker:1.2' 
    testCompile "org.powermock:powermock-api-mockito:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' 
    // Connected Tests 
    androidTestCompile 'org.mockito:mockito-core:1.10.19' 
} 

android { 
    compileSdkVersion 23 
    buildToolsVersion '25.0.0' 

    defaultConfig { 
     minSdkVersion 15 
     targetSdkVersion 19 
     multiDexEnabled true 
    } 

    lintOptions { 
     abortOnError false 
    } 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_7 
     targetCompatibility JavaVersion.VERSION_1_7 
    } 
    dataBinding { 
     enabled = true 
    } 
} 

apply plugin: 'maven' 
apply plugin: 'signing' 

def isSnapshot = version.endsWith('-SNAPSHOT') 
def ossrhUsername = hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 
def ossrhPassword = hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 

task setVersion { 
    // The version will be derived from source 
    project.version = null 
    def sdkVersionFile = file('src/main/java/com/facebook/FacebookSdkVersion.java') 
    sdkVersionFile.eachLine{ 
     def matcher = (it =~ /(?:.*BUILD = \")(.*)(?:\".*)/) 
     if (matcher.matches()) { 
      project.version = matcher[0][1] 
      return 
     } 
    } 
    if (project.version.is('unspecified')) { 
     throw new GradleScriptException('Version could not be found.', null) 
    } 
} 

uploadArchives { 
    repositories.mavenDeployer { 
     beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 

     repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { 
      authentication(userName: ossrhUsername, password: ossrhPassword) 
     } 

     snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { 
      authentication(userName: ossrhUsername, password: ossrhPassword) 
     } 

     pom.project { 
      name 'Facebook-Android-SDK' 
      artifactId = 'facebook-android-sdk' 
      packaging 'aar' 
      description 'Facebook Android SDK' 
      url 'https://github.com/facebook/facebook-android-sdk' 

      scm { 
       connection 'scm:[email protected]:facebook/facebook-android-sdk.git' 
       developerConnection 'scm:[email protected]:facebook/facebook-android-sdk.git' 
       url 'https://github.com/facebook/facebook-android-sdk' 
      } 

      licenses { 
       license { 
        name 'Facebook Platform License' 
        url 'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt' 
        distribution 'repo' 
       } 
      } 

      developers { 
       developer { 
        id 'facebook' 
        name 'Facebook' 
       } 
      } 
     } 
    } 
} 

uploadArchives.dependsOn(setVersion) 

signing { 
    required { !isSnapshot && gradle.taskGraph.hasTask("uploadArchives") } 
    sign configurations.archives 
} 

task androidJavadocs(type: Javadoc) { 
    source = android.sourceSets.main.java.srcDirs 
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 
    // JDK 1.8 is more strict then 1.7. Have JDK 1.8 behave like 1.7 for javadoc generation 
    if (org.gradle.internal.jvm.Jvm.current().getJavaVersion() == JavaVersion.VERSION_1_8) { 
     options.addStringOption('Xdoclint:none', '-quiet') 
    } 
} 

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 
    classifier = 'javadoc' 
    from androidJavadocs.destinationDir 
} 

task androidSourcesJar(type: Jar) { 
    classifier = 'sources' 
    from android.sourceSets.main.java.sourceFiles 
} 

artifacts { 
    archives androidSourcesJar 
    archives androidJavadocsJar 
} 

afterEvaluate { 
    androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath 
} 

點擊Upgrade plugin and sync project沒有做任何事情。

我試過「無效的緩存並重新啓動」建議各種來源,但它沒有奏效。我已經在我的項目build.gradle中提到了gradle插件的最新版本。

我已經通過Gradle DSL Method not found: testCompile()但它不能解決我的問題。

我該怎麼做才能消除這個編譯錯誤?

TIA

編輯1: 我所做的改變由SM4的建議,而這DSL方法沒有發現錯誤去了,但現在它失敗,出現以下錯誤編譯:

Compile error

回答

1
def powerMockVersion = '1.6.1' 
testCompile "org.powermock:powermock-module-junit4:$powerMockVersion" testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion" testCompile "org.powermock:powermock-classloading-xstream:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker:1.2' 
testCompile "org.powermock:powermock-api-mockito:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' 
// Connected Tests 
androidTestCompile 'org.mockito:mockito-core:1.10.19' 

testCompile實際上是對方法的調用。由於在一行上有多個testCompile,因此它被視爲對具有多個參數的方法的調用。這種方法不存在。

只保留一個定義每行,它應該工作:

testCompile "org.powermock:powermock-module-junit4:$powerMockVersion" 
testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion" 
testCompile "org.powermock:powermock-classloading-xstream:$powerMockVersion" 
androidTestCompile 'com.google.dexmaker:dexmaker:1.2' 
testCompile "org.powermock:powermock-api-mockito:$powerMockVersion" 
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' 
+0

Thnx。有效。但是還有另一個彈出的錯誤。 @ sm4請看看我提出的編輯問題。 –

0

試圖通過@ SM4提及該修補程序我決定,我所提到的初始發行後,但它創造了書面問題的EDIT 1節的另一個問題。

我跟着this answer然後最後我的項目編譯沒有任何錯誤。

相關問題