Fabric with Android Studio

大憨熊 提交于 2019-12-23 16:45:03

问题


I'm trying to install Crashlytics trough Fabric into my Android Studio Project I'm running into the following error:

Gradle tasks [:App:generateDebugSources, :App:generateDebugAndroidTestSources, :Customer:generateDebugSources, :Customer:generateDebugAndroidTestSources, :PDFViewCtrlTools:generateDebugSources, :PDFViewCtrlTools:generateDebugAndroidTestSources]
Crashlytics was applied to an android-library project. 
Android-library support is currently an incubating feature. 
Contact support@fabric.io with any issues.
Error:A problem occurred configuring project ':Customer'.
> Could not resolve all dependencies for configuration ':Customer:_debugCompile'.
  > Could not find com.crashlytics.sdk.android:crashlytics:2.2.1.
    Searched in the following locations:
       https://jcenter.bintray.com/com/crashlytics/sdk/android/crashlytics/2.2.1/crashlytics-2.2.1.pom
       https://jcenter.bintray.com/com/crashlytics/sdk/android/crashlytics/2.2.1/crashlytics-2.2.1.jar
       file:/Users/mes/Documents/Eclipse/sdk/extras/android/m2repository/com/crashlytics/sdk/android/crashlytics/2.2.1/crashlytics-2.2.1.pom
       file:/Users/mes/Documents/Eclipse/sdk/extras/android/m2repository/com/crashlytics/sdk/android/crashlytics/2.2.1/crashlytics-2.2.1.jar
       file:/Users/mes/Documents/Eclipse/sdk/extras/google/m2repository/com/crashlytics/sdk/android/crashlytics/2.2.1/crashlytics-2.2.1.pom
       file:/Users/mes/Documents/Eclipse/sdk/extras/google/m2repository/com/crashlytics/sdk/android/crashlytics/2.2.1/crashlytics-2.2.1.jar
       Required by:
       project:Customer:unspecified > project:App:unspecified
    Information:BUILD FAILED

This is my build.gradle:

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

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

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


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

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.android.gms:play-services:6.1.71'
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(":PDFViewCtrlTools")
    compile('com.crashlytics.sdk.android:crashlytics:2.2.1') {
        transitive = true;
    }
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"


    lintOptions {
        // If true, stop the gradle build if errors are found
        abortOnError false
        //ignore 'ValidFragment'
    }
}

This is my AndroidManifest.xml

        <activity
        android:name="com.ecrome.tabook.MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="xxxxxx" />
        </activity>

Any ideas why I'm getting the error and I'm not able to compile the app?


回答1:


Have two build.gradle In first of the project/build.gradle add:

buildscript {
    repositories {
      //ADD this Line
      maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        //ADD this Line
        classpath 'io.fabric.tools:gradle:1.22.2'
    }
 }

And in second app/build.gradle

buildscript {
    repositories {
      //ADD this Line
      maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        //ADD this Line
        classpath 'io.fabric.tools:gradle:1.22.2'
    }
 }

 apply plugin: 'io.fabric'

 repositories {
      maven { url 'https://maven.fabric.io/public' }
 }
 dependencies {
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar'){
         transitive = true;
    }
 }

AndroidManifest

<uses-permission android:name="android.permission.INTERNET" />

<application
    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="yourKey" />
<application/>

MainActivity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_main);
}



回答2:


Change this part, adding the @aar notation

compile('com.crashlytics.sdk.android:crashlytics:2.2.1@aar') {
        transitive = true;
    }

In this way you will download the aar artifact from the repo.




回答3:


One mistake you did is that you have added meta-data inside of activity.

it should be outside of <activity tag and inside of <application tag

And make sure you have initialize fabrics once in Application or Activity startUp.

Fabric.with(mContext, new Crashlytics());


来源:https://stackoverflow.com/questions/30507688/fabric-with-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!