0

我的Crashlytics在我的應用程序中工作。在Android模塊中使用CrashAnalytics

我已將Android模塊添加到名爲'engine-module'的App中,該模塊具有自己的Gradle依賴關係。

我不知道如何正確地導入Crashlytics依賴,我只是得到了以下錯誤:

Error:(31, 13) Failed to resolve: com.crashlytics.sdk.android:crashlytics:2.6.5

我想實現的是能夠從內一類訪問「Crashlytics」的'發動機模塊」,例如:

Crashlytics.setUserName("temp user name"); 

這可能嗎?如果是這樣,怎麼能實現?

項目:的build.gradle

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.3' 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

subprojects { 
    apply from: '../jacoco.gradle' 
} 

應用/的build.gradle

buildscript { 
    repositories { 
     maven { url 'https://maven.fabric.io/public' } 
    } 

    dependencies { 
     classpath 'io.fabric.tools:gradle:1.+' 
    } 
} 
apply plugin: 'com.android.application' 
apply plugin: 'io.fabric' 

repositories { 
    maven { url 'https://maven.fabric.io/public' } 
} 

apply plugin: 'com.neenbedankt.android-apt' 

/** 
* Default values for configuration options 
*/ 
def suffixDefault = "" 
def versionCodeDefault = 1 
def versionNameDefault = "developerBuilt" 

/** 
* Android-specific configuration 
*/ 
android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 
    defaultConfig { 
     applicationId "com.flowmellow.projectx 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode project.getProperties().get('versionCode') ? project.getProperties().get('versionCode').toInteger() : versionCodeDefault 
     versionName project.getProperties().get('versionName') ? project.getProperties().get('versionName') : versionNameDefault 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     debug { 
      // Configurable options 
      applicationIdSuffix project.getProperties().get('appIdSuffix', suffixDefault) + ".debug" 

      // Common options 
      testCoverageEnabled true 
     } 
     release { 
      // Configurable options 
      applicationIdSuffix project.getProperties().get('appIdSuffix', suffixDefault) 

      // Common options 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

/** 
* Dependencies 
*/ 
dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:25.0.0' 
    compile 'com.android.support:design:25.0.0' 

    //Dependency injection 
    apt 'com.google.dagger:dagger-compiler:2.7' 
    compile 'com.google.dagger:dagger:2.7' 
    provided 'javax.annotation:jsr250-api:1.0' 

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 

    testCompile 'junit:junit:4.12' 
    testCompile 'org.hamcrest:hamcrest-library:1.1' 
    testCompile 'org.mockito:mockito-core:1.9.5' 
    testCompile 'org.robolectric:robolectric:3.1.2' 
    testCompile 'org.hamcrest:hamcrest-library:1.1' 
    compile 'com.android.support.constraint:constraint-layout:+' 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     transitive = true; 
    } 
    compile project(path: ':engine-module') 

} 

模塊:發動機模塊/的build.gradle

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 

    defaultConfig { 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 

    compile 'com.android.support:support-annotations:25.0.0' 

    testCompile 'junit:junit:4.12' 
    testCompile 'org.mockito:mockito-core:1.9.5' 
    testCompile 'org.robolectric:robolectric:3.1.2' 
    compile 'com.crashlytics.sdk.android:crashlytics:2.6.5' 
} 

解決:

項目:的build.gradle

buildscript { 
    repositories { 
     jcenter() 
     maven { url 'https://maven.fabric.io/public' } 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.3' 
     classpath 'io.fabric.tools:gradle:1.+' 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
     maven { url 'https://maven.fabric.io/public' } 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

subprojects { 
    apply from: '../jacoco.gradle' 
} 

模塊:發動機模塊/的build.gradle

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

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 

    defaultConfig { 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 

    compile 'com.android.support:support-annotations:25.0.0' 

    testCompile 'junit:junit:4.12' 
    testCompile 'org.mockito:mockito-core:1.9.5' 
    testCompile 'org.robolectric:robolectric:3.1.2' 

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

回答

1

你沒有定義任何資源庫爲engine-module模塊,這意味着它不能解決相關的依賴關係。

一般人通過添加以下代碼到根build.gradle

subprojects { 
    repositories { 
     // Add repositories here 
    } 
} 

這使得可用於所有子項目這些庫定義了他們的整個項目庫。

+0

謝謝你是我的問題,不使用root build.gradle –

相關問題