gradle sync keeps failing with my android studio. need help
https://github.com/linkedin/dexmaker This is the open source i am trying to use called dexmaker.
I tried to download by using
androidTestCompile 'com.linkedin.dexmaker:dexmaker-mockito-inline:2.21.0'
but it gets errors like this
Failed to resolve: com.linkedin.dexmaker:dexmaker-mockito-inline:2.21.1
I finally tried
androidTestCompile 'com.linkedin.dexmaker:dexmaker-mockito-inline:2.19.1'
this works but in my java code
The problem is even though i succeeded on syncing gradle, i still can't use the opensource.
DexMaker dexMaker = new DexMaker();
DexMaker gets red lines and if i click it it says
cannot resolve symbol 'DexMaker'
what's the problem?
I'm not sure, but as I understand your situation:
You add dependency using androidTestCompile directive. That means that this package will become available only inside android test classes. For more understanding each dependency could be added in three ways: compile, testCompile and androidTestCompile.
compile : Dependency is available everywhere in your application code.
testCompile : Dependency available only in regular tests.
androidTestCompile : Dependency available only in android tests.
So if you want that dependency to be available in your application - replace androidTestCompile with compile. But I not sure, that you SHOULD do that, cause that library is for tests.
P.S. Using compile directives is deprecated and you should use implementation, testImplementation and androidTestImplementation.
Related
I'm getting the next crash when I launch my Android app after adding the first Dagger module.
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/collect/ImmutableMap;
at com.sofaking.moonworshipper.DaggerAppComponent.getMapOfClassOfAndProviderOfFactoryOf(DaggerAppComponent.java:35)
at com.sofaking.moonworshipper.DaggerAppComponent.getDispatchingAndroidInjectorOfActivity(DaggerAppComponent.java:41)
at com.sofaking.moonworshipper.DaggerAppComponent.injectApp(DaggerAppComponent.java:64)
at com.sofaking.moonworshipper.DaggerAppComponent.inject(DaggerAppComponent.java:59)
at com.sofaking.moonworshipper.DaggerAppComponent.inject(DaggerAppComponent.java:16)
The issue seems to be identical to this one on GitHub:
https://github.com/google/dagger/issues/897
I understand that Dagger is trying to use Guava, although it shouldn't - But I'm not sure what to do to fix this. It's not a proguard issue.
I tried to include guava in my dependencies - which presented the next error while compiling:
Error: Program type already present: com.google.common.util.concurrent.internal.InternalFutures
which makes sense, as there are other libraries in my code which depend on guava.
implementation 'com.google.dagger:dagger:2.15'
kapt 'com.google.dagger:dagger-compiler:2.15'
compile 'com.google.dagger:dagger-android:2.15'
compile 'com.google.dagger:dagger-android-support:2.15'
kapt 'com.google.dagger:dagger-android-processor:2.15'
// tried adding this as well, didn't work
api 'com.google.guava:guava:27.0-android'
Edit: Here's tree of resolved dependecies: https://pastebin.com/RsPPjD6H
After seeing that Dagger depends on com.google.guava:guava:23.3-jre, I tried adding the next line in my Gradle build file:
api 'com.google.guava:guava:23.3-android'
And it works!
The word "compile" is not used anymore. Use "implementation" instead in your dependencies. I don't know if that is causing the issue but maybe.
Referring to https://developer.android.com/training/testing/unit-testing/local-unit-tests.html and https://medium.com/#ali.muzaffar/the-basics-of-unit-and-instrumentation-testing-on-android-7f3790e77bd, I added
testCompile 'junit:junit:4.12'
in my gradle. Then I created a new test class, but apparently
#Test
throws 'Cannot resolve symbol'. On pressing ALT + Enter, Android Studio suggested me to 'Add testng to classpath'.
I don't quite understand what's going on here. I thought I don't need testng for what I'm trying to do here, nor the 2 articles above also didn't mention anything about testng.
Furthermore if I followed the Android Studio suggestion to 'Add testng to classpath', Android Studio will automatically add
androidTestCompile 'org.testng:testng:6.9.6'
in my gradle. And when I try to run the test, I will get the error
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/Description;
Apparently changing
testCompile 'junit:junit:4.12'
to
androidTestCompile 'junit:junit:4.12'
solves this. Android Studio also won't bug me to add testng to classpath.
This Confused about testCompile and androidTestCompile in Android Gradle also helped me to understand more about testCompile vs androidTestCompile
I want to setup my project for unit testing.
I tried to follow the instructions on Android's page:
// Unit testing dependencies
testCompile 'junit:junit:4.12'
// Set this dependency if you want to use Mockito
testCompile 'org.mockito:mockito-core:1.10.19'
// Set this dependency if you want to use Hamcrest matching
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
However, when doing that and creating a test, I get:
"Cannot resolve symbol 'junit'"
"Cannot resolve symbol 'mockito'"
In Vogel's tutorial, a lot more dependencies are required, and I want the bare minimum.
Also, using Vogel's tutorial, I get:
Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.2.1) and test app (22.2.0) differ.
So my question is: How can I get the dependencies from Android's page to work?
The support-annotations issue is a known one. You can find the info in their issue tracker. To workaround it, in the main (app, not module) build.gradle file, section allprojects add
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
}
(see answer #11 in the same link).
About the extra dependencies, you are going to need dexmaker and dexmaker-mockito for using mockito for your tests in devices/emulator, as they run on a Dalvik VM that expects .dex files, while mockito generates .class files. Unit testing as in the newest unit testing added to Android Studio, runs in your local JVM so it should probably run without dexmaker, but I cannot confirm this as of yet.
We have a project with some library (and native) dependencies, like this:
Native SDK ← Library (Wrapper) ← Main Project
To start with, this structure cannot be changed, as we are reusing the parts. The problem I am facing is passing the 65k reference limit. This, of course, has a workaround - enable ProGuard. With it enabled, the project compiles.
Since we are transitioning to the Android's default testing framework, we need to add some more dependencies to the testing config, so in dependencies we now have:
compile 'com.google.android.gms:play-services-base:7.5.0'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-safetynet:7.5.0'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
compile files('libs/small-library1.jar')
compile files('libs/small-library2.jar')
compile files('libs/small-library3.jar')
compile files('libs/medium-library1.jar')
compile files('libs/medium-library2.jar')
compile files('libs/medium-library3.jar')
compile files('libs/huge-library1.jar')
compile files('libs/huge-library2.jar')
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
We are using SDK (API) 22, so everything is pretty much at the latest version. The problem is, our native SDK has a bunch of code in the protobuf layer, and the library wrapper is big. With all other JARs, we are too high over the 65k limit (but as I said, ProGuard fixes this barely). Multi-dex is out of the question as it works well only on Android 5.0+.
We're trying to reduce the codebase, but even then, Android Tests are failing with method reference overflow issues (i.e. not compiling).
Is there any way to enable ProGuard for tests as well?
One option is to change your test build using testBuildType to the release build or another build variant that has ProGuard enabled. See Gradle User Guide. You can also try the solution here, but I have not tried that myself.
How to attach sources from android.support.test.* for debugging in AS?
Tried downloading sources from https://android.googlesource.com/platform/frameworks/testing but the version doesn't seem to match my testing library version.
Testing sources (for instance AndroidJunitRunner) don't seem to be available via sdk manager, am I missing something ?
I encountered a similar problem and it took a quite amount of time to figure it out. It seems like a bug due to a missing Gradle task not executed because the SAME configuration used to work but not any more after upgrading to AS v1.2+.
First, the following dependency is obsolete.
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
And it is updated as follows in the documentation.
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
...
The defaultConfig should include the following line as usual.
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Also, make sure the Android Support Repository is installed through the SDK Manager.
If android.support.test.* cannot be resolved, then manually execute the Gradle task as follows.
Click the Gradle tab on the right.
Collapse your Android module and brow the Tasks node.
Double click to execute other->generateDebugAndroidTestSources
If succeeded, the issue may be solved. At least, it works for me.
UPDATE:
It seems like there are still chances this could happen on AS 2.1.2. To be noted, if you have more than one Android modules, running the gradle task generateDebugAndroidTestSources from one particular should be enough for all, especially the Android library module one.
I suffered this problem recently and I solve it now.
After I add the following dependencies and Sync Project with Gradle file, I can not find any relative library in the External Library folder.
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
What I do is to replace all androidTestCompile to compile and Sync Project with Gradle file. and I can see the relative libraries.
Last, I replace compile back to androidTestCompile and Sync Project with Gradle file again. The relative libraries are still there.
I want to post images to make it more clearly, but I am new in here and can not post images.
Hope this will help you.
You can use Espresso for UI-tests and Robolectric + JUnit + Mockito for unit-tests.
Use AndroidJunitRunner, add it to build.gradle like:
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
Use some package android.support.test.* you need add dependencies like
dependencies {
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude module: 'support-annotations'
}
}