2015-09-04 67 views
2

這是我的build.gradle文件:如何正確添加appcompat庫到android項目?

buildscript { 
    repositories { 
     mavenCentral() 

     // Configuration for Fabric 
     jcenter() 
    maven { url 'https://maven.fabric.io/public' } 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:1.2.3' 
     classpath 'io.fabric.tools:gradle:1.+' 
    } 
} 

apply plugin: 'com.android.application' 
apply plugin: 'io.fabric' 

dependencies { 
    // 'jar' files in '/libs' folder 
    compile fileTree(dir: 'libs', include: '*.jar') 

    compile 'com.facebook.android:facebook-android-sdk:4.1.0' 
    compile 'com.google.android.gms:play-services-gcm:7.8.0' 

    // Fabric 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     transitive = true; 
    } 
} 

repositories { 
    mavenCentral() 

    // Configuration for Fabric 
    jcenter() 
    maven { url 'https://maven.fabric.io/public' } 
} 

android { 
    compileSdkVersion 15 
    buildToolsVersion 22 

    // Define current date and time now to have the same all along the build 
    def currentDate = getCurrentDate() 
def currentDateAndTime = getCurrentDateAndTime() 

    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['assets'] 
      jniLibs.srcDirs = ['libs'] 
     } 
    } 

    defaultConfig { 
     versionCode 2.7 
     versionName name 
     minSdkVersion 15 
     targetSdkVersion 22 
    } 

    productFlavors { 
     x86 { 
      flavorDimension "abi" 
      ndk { 
       abiFilter "x86" 
      } 
     } 
     arm { 
      flavorDimension "abi" 
      ndk { 
       abiFilter "armeabi-v7a" 
      } 
     } 
    } 


    buildTypes { 
     // Configuration for release candidates 
     release { 

      // Proguard configuration 
      minifyEnabled true 
      proguardFile 'procfg.pro' 

     } 


    lintOptions { 
     abortOnError false 
    } 
} 

添加的依賴後,程序兼容性:

.... 
dependencies { 
    // new dependency added 
    compile 'com.android.support:appcompat-v7:22.0.0' 
    // 'jar' files in '/libs' folder 
    compile fileTree(dir: 'libs', include: '*.jar') 

    compile 'com.facebook.android:facebook-android-sdk:4.1.0' 
    compile 'com.google.android.gms:play-services-gcm:7.8.0' 

    // Fabric 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     transitive = true; 
    } 
} 
.... 

,我發現了以下錯誤:

AGPBI: {"kind":"ERROR","text":"Attribute \"textAllCaps\" has already been defined","sourcePath":"<dir>/colors.xml","position":{"startLine":1},"original":""} 
AGPBI: {"kind":"ERROR","text":"Attribute \"track\" has already been defined","sourcePath":"<dir>/colors.xml","position":{"startLine":1},"original":""} 
AGPBI: {"kind":"ERROR","text":"Attribute \"thumbTextPadding\" has already been defined","sourcePath":"<dir>/colors.xml","position":{"startLine":1},"original":""} 
AGPBI: {"kind":"ERROR","text":"Attribute \"switchMinWidth\" has already been defined","sourcePath":"<dir>/colors.xml","position":{"startLine":1},"original":""} 
AGPBI: {"kind":"ERROR","text":"Attribute \"switchPadding\" has already been defined","sourcePath":"<dir>/colors.xml","position":{"startLine":1},"original":""} 

我已經定義了無這個值在我的color.xml文件中。我想這個問題可能與Facebook的SDK庫有關。

讓我知道你是否需要更多信息。

+0

發佈其他依賴項 –

+0

@GabrieleMariotti我添加了依賴關係。 – JoseF

+0

你在使用一些罐子嗎? –

回答

0

首先,您可以嘗試使用appcompat-v7 22.2.1的最新版本v22。 如果仍然存在問題,請使用gradle和模塊的名稱檢查依賴關係列表:依賴關係。如果我的模塊是應用程序嘗試在一個終端:

gradle app:dependencies 

(或gradlew如果您使用的是漸進式包裝)。 你應該有這樣的事情:

+--- com.android.support:appcompat-v7:22.2.1 
    | \--- com.android.support:support-v4:22.2.1 
    |   \--- com.android.support:support-annotations:22.2.1 
    \--- com.facebook.android:facebook-android-sdk:4.1.0 
     +--- com.android.support:support-v4:[21,22) -> 22.2.1 (*) 
     \--- com.parse.bolts:bolts-android:1.2.0 

你可以看到,無論是程序兼容性-V7和Facebook,Android的SDK自己的支持-V4。 要排除來自Facebook的SDK支持-V4,你將不得不寫:

compile ('com.facebook.android:facebook-android-sdk:4.1.0') { 
    exclude group:'com.android.support', module: "support-v4" 
} 

如果您運行的gradle以前的應用程序:依賴,你會看到,現在的Facebook SDK沒有支持-V7在其子目錄中。

希望這會幫助你。

+0

目前最新版本的appcompat不是22.2.1,而是23.0.0 –

+0

是的你是對的,我應該說最新版本爲api 22. – xiaomi

+0

我已經排除了Facebook上的support-v4,並且我仍然收到相同的錯誤 – JoseF

相關問題