gpt4 book ai didi

android - com.crashlytics.android.CrashlyticsMissingDependencyException 在 android studio 项目上的 gradle 'testDebug' 期间

转载 作者:可可西里 更新时间:2023-11-01 19:05:02 25 4
gpt4 key购买 nike

我有一个带有最新 1.15.2 crashlytics 的 Android Studio 项目。当我在我的设备上构建和运行时,它运行良好。然而,在 crashlytic 的设置之后,我的测试在 gradle 'testDebug' 上失败了。

输出是

....app.entity.ConfigurationTest > parseTest FAILED
java.lang.RuntimeException
Caused by: io.fabric.sdk.android.services.concurrency.UnmetDependencyException
Caused by: com.crashlytics.android.CrashlyticsMissingDependencyException

它可能与测试准备期间调用 Activity onCreate 方法有关。在 onCreate 我有一行

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

看起来它在 test 范围内的工作方式不同。

我如何解决这个问题或在测试期间完全跳过 crashlytics?F.e.这是一个适用于一个人的解决方案,但它对我不起作用,或者我把它放在无效的 gradle 部分。

debug {
ext.enableCrashlytics = false
}

CrashlyticsMissingDependencyException

构建.gradle

buildscript {
repositories {
jcenter()
}
repositories { mavenCentral() }
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'org.robolectric:robolectric-gradle-plugin:0.14.0'
}
}

allprojects {
repositories {
jcenter()
}
}

应用程序/应用程序.gradle

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

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

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

apply plugin: 'robolectric'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId “…”
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName “…”
}
signingConfigs {
debug {

}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.debug
ext.enableCrashlytics = false
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services-location:6.5.87'
compile 'com.facebook.android:facebook-android-sdk:3.23.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup:otto:1.3.6'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'

provided 'com.squareup.dagger:dagger-compiler:1.2.0'
compile 'com.squareup.dagger:dagger:1.2.0'

compile 'com.stripe:stripe-android:1.0.0'

androidTestCompile 'junit:junit:4.10'
androidTestCompile ('org.robolectric:robolectric:2.3')
androidTestCompile "org.mockito:mockito-core:1.10.19"
compile('com.crashlytics.sdk.android:crashlytics:2.2.1@aar') {
transitive = true;
}
}

查看测试结果文件后的更多输出

java.lang.RuntimeException: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: com.crashlytics.android.CrashlyticsMissingDependencyException: 
This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up,
install an Android build tool and ask a team member to invite you to this app's organization.

at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:240)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: com.crashlytics.android.CrashlyticsMissingDependencyException:
This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up,
install an Android build tool and ask a team member to invite you to this app's organization.

at com.crashlytics.android.Crashlytics.onPreExecute(Crashlytics.java:347)
at com.crashlytics.android.Crashlytics.onPreExecute(Crashlytics.java:229)
at io.fabric.sdk.android.InitializationTask.onPreExecute(InitializationTask.java:27)
at io.fabric.sdk.android.services.concurrency.AsyncTask.executeOnExecutor(AsyncTask.java:594)
at io.fabric.sdk.android.services.concurrency.PriorityAsyncTask.executeOnExecutor(PriorityAsyncTask.java:26)
at io.fabric.sdk.android.Kit.initialize(Kit.java:49)
at io.fabric.sdk.android.Fabric.initializeKits(Fabric.java:417)
at io.fabric.sdk.android.Fabric.init(Fabric.java:364)
at io.fabric.sdk.android.Fabric.setFabric(Fabric.java:321)
at io.fabric.sdk.android.Fabric.with(Fabric.java:292)
at app.AppApplication.onCreate(AppApplication.java:32)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:164)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:430)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
... 35 more
Caused by: com.crashlytics.android.CrashlyticsMissingDependencyException:
This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up,
install an Android build tool and ask a team member to invite you to this app's organization.

at com.crashlytics.android.BuildIdValidator.validate(BuildIdValidator.java:59)
at com.crashlytics.android.Crashlytics.onPreExecute(Crashlytics.java:306)
... 48 more

解决方法(对我有用)

我暂时使用以下方法为我修复了它:我创建了一个类

public class CrashlyticsFacade {

public static boolean enableCrashlytics = true;

public static void initCrashlytics(Application application) {
if (enableCrashlytics) {
Fabric.with(application, new Crashlytics());
}
}

public static void log(int priority, String tag, String msg) {
if (enableCrashlytics) {
Crashlytics.log(priority, tag, msg);
}
}

public static void identify(String userIdentifier, String userName, String email) {
if (enableCrashlytics) {
if (userIdentifier != null) {
Crashlytics.setUserIdentifier(userIdentifier);
}
if (userName != null) {
Crashlytics.setUserName(userName);
}
if (email != null) {
Crashlytics.setUserEmail(email);
}
}
}

public static void setEnableCrashlytics(boolean value) {
CrashlyticsFacade.enableCrashlytics = value;
}

我在应用程序代码和测试中将它用作 Crashlytics 的门面。另外在测试课上我必须使用

@BeforeClass
public static void beforeClass() {
CrashlyticsFacade.setEnableCrashlytics(false);
}

因为 robolectric 使用单独的类加载器进行测试

最佳答案

我找到了另一个解决方案。如果您在测试中使用 robolectric(如果没有,您可以添加它或使用@Rostislav 提供的答案),您可以覆盖您的应用程序类并跳过 Crashlytics 初始化。

// MyApplication.java in src\main\java

public class MyAplication extends Application {

@Override
public void onCreate() {
super.onCreate();
setupCrashlytics();
}

protected void setupCrashlytics() {
Fabric.with(this, new Crashlytics());
}
}

=======

// TestMyAplication.java in src\test\java
/**
* Robolectric uses class with name Test<ApplicationClassName> as test variant of the application
* class. We use test application for API class injection so we need test version of this class.
*/
public class TestMyAplication extends MyAplication {

@Override
protected void setupCrashlytics() {
// nothing
}
}

关于android - com.crashlytics.android.CrashlyticsMissingDependencyException 在 android studio 项目上的 gradle 'testDebug' 期间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28762624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com