Can't run unit tests in Android Studio - android

I'm trying to make my unit tests work again for two days now, every time that I try to run them I get this error:
Process finished with exit code 1
Class not found: "XXXXX.XXXXX.XXXXX.XXX"Empty test suite.
This happens trying to run both the test class, or just the methods. I've tried to clean all the test configurations and rebuild the project. Furthermore, I was able to find other people having the same problem, therefore, the proposed solutions were not effective to fix my issue.
This is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
defaultConfig {
applicationId "XXXXXXXXXX"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0.0"
multiDexEnabled true
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.4.0'
}
}
apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'
ext {
supportLibVersion = '25.1.0' // variable that can be referenced to keep support libs consistent
jomlVersion = '1.8.4'
}
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile "com.android.support:support-v4:${supportLibVersion}"
compile('com.crashlytics.sdk.android:crashlytics:2.6.5#aar')
{
transitive = true;
}
compile project(':circular-slider')
compile project(':gpuimage-plus')
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'net.protyposis.android.mediaplayer:mediaplayer:4.2.2-rc1'
compile 'net.protyposis.android.mediaplayer:mediaplayer-dash:4.2.2-rc1'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.writingminds:FFmpegAndroid:0.3.2'
compile 'com.makeramen:roundedimageview:2.3.0'
compile 'io.reactivex:rxjava:1.2.4'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'com.minimize.android:rxrecycler-adapter:1.2.2'
compile "org.joml:joml:${jomlVersion}"
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'org.jetbrains:annotations-java5:15.0'
compile 'com.annimon:stream:1.1.3'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.powermock:powermock-api-mockito:1.6.5'
testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.6.5'
testCompile 'org.powermock:powermock-module-junit4-rule:1.6.5'
testCompile 'org.powermock:powermock-module-junit5:1.6.5'
compile 'com.google.android.gms:play-services-appindexing:8.4.0'
compile 'com.android.support:multidex:1.0.1'
}
And the beginning of the class with the tests:
#PrepareForTest({XXXXXX.class, XXXXXX.class, XXXXXX.class, XXXXXX.class})
#RunWith(PowerMockRunner.class)
public class VideoPlayerModelUnitTest {
Thanks!
Update
I was able to fix partially the problem by changing the references in my AndroidMaifest file.
Therefore, changing the references from:
<activity android:name="com.myapp.MusicSelector.MusicSelectorActivity"/>
To:
<activity android:name=".MusicSelector.MusicSelectorActivity"/>
However, I can't create new tests or even rename my tests methods. For example, if I rename from:
#Test
public void testVideoListToTimedClips() throws Exception {
to:
#Test
public void testVideoListToTimedClips2() throws Exception {
I get the error:
java.lang.Exception: No tests found matching Method testVideoListToTimedClips2(io.collect.collect.functional.VideoPlayerModelIntegrationTest) from org.junit.internal.requests.ClassRequest#15eb5ee5
Update 2
Trying things out, seems like Android Studio is keeping the reference to the an old version of the tests.
I changed the name of the test method from testVideoListToTimedClips to testVideoListToTimedClips2 resulting in a test class like that:
#PrepareForTest({VideoPlayerModel.class, MediaPlayer.class, Common.class})
#RunWith(PowerMockRunner.class)
public class testVideoPlayerModelIntegration {
#Test
public void testVideoListToTimedClips2() throws Exception {
And when I run the test class, Android Studio runs the old method:

Are you using Android Studio 2.3.0-beta1? If so, there's a bug that causes your unit tests to not get built when you try to run them.
You can work around the issue by first running Make project and then Run each time you want to run the unit tests.
This issue is supposed to be fixed in the next canary/beta version of Android studio.
Source:
https://code.google.com/p/android/issues/detail?id=230688

I was facing similar type of issue.
I was building using following command :
gradle clean build -x test
This skips the test cases.
instead try : gradle clean build
Clean your project in IDE. This will load latest class file and refresh its references.

I had similar issue. You need to check whether the issue is in the code or android studio. try run unit test using command prompt / terminal
./gradlew testDevelopDebugUnitTest
DevelopDebug is flavour that I have in the code so it might be different with yours. If that command is executed successfully then the issue is in android studio.
Once I run this command manually then the issue fix itself ( I'm not sure the reason though ). Hopefully can help you guys. Thank you

I was able to fix the problem by changing the references in the Manifest file from:
<activity android:name="com.myapp.MusicSelector.MusicSelectorActivity"/>
To:
<activity android:name=".MusicSelector.MusicSelectorActivity"/>
Also, after every change on the tests I need to make my project manually.

At some point you should declare your test runner in the module gradle config. For example inside defaultConfig:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Right click on the class which you want to test and click run.

Related

Error [DuplicatePlatformClasses] class conflict when building release on Room persistence

I have used this guide to build persistence with Room in my Android App:
https://developer.android.com/training/data-storage/room/index.html
and added dependances like shown here:
https://developer.android.com/topic/libraries/architecture/adding-components.html
when i build the debug version and deply to phone, everithing works fine.
When i build the release signed APK i got this error message:
Error:Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
my app.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
/* TODO(developer): Configure to sign app with a release key for testing.
release {
storeFile file('path/to/release/signing/key')
keyAlias 'release_key_alias'
keyPassword "${password}"
storePassword "${password}"
}*/
}
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "myappid"
minSdkVersion 14
targetSdkVersion 23
versionCode 10
versionName "1.8"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// TODO(developer): uncomment below once config above is complete and uncommented.
//signingConfig signingConfigs.release
}
}
}
configurations {
all {
exclude module: 'httpclient'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.1.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.github.nkzawa:socket.io-client:0.3.0'
compile 'io.socket:socket.io-client:0.8.3'
compile 'com.android.support:design:26.1.0'
compile 'android.arch.persistence.room:runtime:1.0.0'
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}
my project.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//classpath 'io.socket:socket.io-client:0.8.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext{
roomVersion = '1.0.0'
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
Somebody can help or give me clues?
I finally found the problem was a JSON sub-module:
compile 'com.github.nkzawa:socket.io-client:0.3.0'
this library has a submodule:
org.json:json
that is now conflicting with android native module, because in my other dependancies i can't find this one. It was working fine 10 days ago.
I also had to kill this:
compile 'io.socket:socket.io-client:0.8.3'
the final solution was to add an exclude for the module and change the line like this:
implementation ('com.github.nkzawa:socket.io-client:0.3.0',{
exclude group:'org.json', module:'json'
})
I also have noticed AFTER i solved the problem that in the error log it was suggesting me the module that was in conflict but even if i read it a hundred times i didn't noticed before:
so maybe google or Intellij could improve the writing of this errors...
To spot this class duplicate conflict error module i found the best way to proceed is to create a new project and paste in the dependancies in app build.gradle, and check them one by one or with "dividi et impera", maybe this is an obvious suggestion for someone but i would have like to have it sooner.
I had the same problem and I searched for the conflict via the gradle dependency tree:
gradlew app:dependencies
Then I excluded the the json module for the conflicting library:
implementation ('<conflicting-library>',{
exclude group:'org.json', module:'json'
})
How to find the duplicate library.
open gradle run window and run such command:
gradle module-name:dependencies
the "module-name" should be your app module's name, for me, it's "osmunda-demo".
then use Ctrl+F to search "commons-logging", you'll find it.
#Romeo has suggested a really great point. Was unable to debug the code for hours. The problem lies within the dependencies that are imported in build.gradle. It may be your own custom sdk/artifact. I had issues with my own library which uses jjwt. I added the exclusion in my sdk but you will have to add it again whenever using the sdk. Make sure to add exclude group: 'org.json', module: 'json' in your artifact implementation.

Android Studio 3.0 Error. Migrate dependency configurations for local modules

I recently installed the latest Canary build of Android Studio which is currently using the Android Gradle plugin 3.0.0-alpha4 .
I now get a error:
Error:Failed to resolve: Could not resolve project :MyLib.
Required by:
project :app
I has read: Migrate dependency configurations for local modules
dependencies
{
// This is the old method and no longer works for local
// library modules:
// debugCompile project(path: ':foo', configuration: 'debug')
// releaseCompile project(path: ':foo', configuration: 'release')
// Instead, simply use the following to take advantage of
// variant-aware dependency resolution. You can learn more about
// the 'implementation' configuration in the section about
// new dependency configurations.
implementation project(':foo')
// You can, however, keep using variant-specific configurations when
// targeting external dependencies. The following line adds 'app-magic'
// as a dependency to only the 'debug' version of your module.
debugImplementation 'com.example.android:app-magic:12.3'
}
I changed:
releaseCompile project(path: ':MyLib', configuration: 'appReleaseApp')
debugCompile project(path: ':MyLib', configuration: 'appDebug')
to:
implementation project(':MyLib')
but i still have this error: Error:Failed to resolve: Could not resolve project :MyLib.
lib gradle:
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
}
buildTypes {
debug {
...
}
releaseApp {
...
}
releaseSdk {
...'
}
}
flavorDimensions "default"
productFlavors {
flavor1{
...
flavor2{
...
}
flavor3{
...
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.google.android.gms:play-services-maps:10.2.6'
compile 'com.google.android.gms:play-services-gcm:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
}
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: mavenLocal().url)
}
}
}
app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion 19
targetSdkVersion 25
versionCode 12
versionName "5.0.2"
}
buildTypes {
release {
...
}
debug {
...
}
}
flavorDimensions "default"
productFlavors {
flavor1 {
...
}
flavor2 {
...
}
}
testOptions {
unitTests {
all {
jvmArgs '-noverify'
systemProperty 'robolectric.logging.enable', true
}
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
// releaseCompile project(path: ':MyLib', configuration: 'appRelease')
// debugCompile project(path: ':MyLib', configuration: 'appDebug')
implementation project(':MyLib')
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.android.gms:play-services-maps:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.android.gms:play-services-analytics:10.2.6'
compile 'com.google.android.gms:play-services-gcm:10.2.6'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'
compile 'com.android.support:percent:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.1.0'
testCompile 'org.robolectric:robolectric:3.1.4'
testCompile 'org.assertj:assertj-core:1.7.1'
compile 'com.flipboard:bottomsheet-core:1.5.0'
compile 'com.flipboard:bottomsheet-commons:1.5.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
}
apply plugin: 'com.google.gms.google-services'
Please help
Google added more instruction how to solve it: Resolve build errors related to dependency matching
Cause of build error:
Your app includes a build type that a library dependency does not.
For example, your app includes a "staging" build type, but a
dependency includes only a "debug" and "release" build type.
Note that there is no issue when a library dependency includes a build
type that your app does not. That's because the plugin simply never
requests that build type from the dependency.
Resolution
Use matchingFallbacks to specify alternative matches for a given build type, as shown below:
// In the app's build.gradle file.
android {
buildTypes {
debug {}
release {}
staging {
// Specifies a sorted list of fallback build types that the
// plugin should try to use when a dependency does not include a
// "staging" build type. You may specify as many fallbacks as you
// like, and the plugin selects the first build type that's
// available in the dependency.
matchingFallbacks = ['debug', 'qa', 'release']
}
}
}
After facing the same issue, I finally declared exactly the same buildTypes in both App and Modules' build.gradle files.
In your case, adding
buildTypes {
debug {}
releaseApp {}
releaseSdk {}
}
to your module's build.gradle should do the trick.
Be sure to change any "compile project" to "implementation project" too.
Hope it helps
With the new plugin, the variant-aware dependency resolution
implementation project(':MyLib')
needs to have exact matching build types. The migration guide describes this
For instance, it is not possible to make a 'debug' variant consume a
'release' variant through this mechanism because the producer and
consumer would not match. (In this case, the name 'debug' refers to
the published configuration object mentioned above in the Publishing
Dependencies section.) Now that we publish two configurations, one for
compiling and one for runtime, this old way of selecting one
configuration really doesn't work anymore.
So the old method of
releaseCompile project(path: ':foo', configuration: 'debug')
will not work anymore.
Example
With your example this would look like this:
In app build.gradle:
apply plugin: 'com.android.application'
android {
buildTypes {
debug {}
releaseApp {}
releaseSdk {}
}
...
dependencies {
implementation project(':MyLib')
}
}
In module/lib 'MyLib' build.gradle:
apply plugin: 'com.android.library'
android {
buildTypes {
debug {}
releaseApp {}
releaseSdk {}
}
}
Therefore the build type must exactly match, no more no less.
Using Build-Type Fallbacks
A new feature called "matchingFallbacks" can be used to define default buildtypes if a sub-module does not define the buildtype.
Use matchingFallbacks to specify alternative matches for a given build type (...)
For example if module/lib 'MyLib' gradle would look like this:
apply plugin: 'com.android.library'
android {
buildTypes {
debug {}
releaseLib {}
}
}
You could define the following in your app build.gradle:
apply plugin: 'com.android.application'
android {
buildTypes {
debug {}
releaseApp {
...
matchingFallbacks = ['releaseLib']
}
releaseSdk {
...
matchingFallbacks = ['releaseLib']
}
}
...
dependencies {
implementation project(':MyLib')
}
}
Missing Flavor Dimensions
Use missingDimensionStrategy in the defaultConfig block to specify the
default flavor the plugin should select from each missing dimension
android {
defaultConfig {
missingDimensionStrategy 'minApi', 'minApi18', 'minApi23'
...
}
}
I was facing the same problem, I found this migration page:
Build matching types
It states:
Select defaults for missing build types
If a consumer configures a build type that a producer does not, you need to manually match the consumer's build type to one from the producer. For example, if your app module configures a "staging" build type and its library module dependency, "mylibrary", does not, the Android plugin throws the following build error:
Error:Failed to resolve: Could not resolve project :mylibrary.
Required by: project :app
To resolve this error, you need to specify which build type from "mylibrary" the Android plugin should match to the app's "staging" build type. You can do this with the buildTypeMatching property in the app's build.gradle file, as shown below:
// Add the following to the consumer's build.gradle file.
android {
...
// Tells the Android plugin to use a library's 'debug' build type
// when a 'staging' build type is not available. You can include
// additional build types, and the plugin matches 'staging' to the
// first build type it finds from the one's you specify. That is,
// if 'mylibrary' doesn't include a 'debug' build type either, the
// plugin matches 'staging' with the producer's 'release' build type.
buildTypeMatching 'staging', 'debug', 'release'
}
Adding buildTypeMatching fixed it for me without creating unecessary types in my library
Today I also had the same problem after migrating to Android Studio 3.
The problem is the gradle is not able to resolve the certain libraries due to network issue. The reasons might be various.
If you work behind the proxy you need to add the proxy parameters in gradle.properties file:
systemProp.http.proxyHost=<proxy_host>
systemProp.http.proxyPort=<proxy_port
systemProp.https.proxyHost=<proxy_host>
systemProp.https.proxyPort=<proxy_port>
In my case I had one more issue. My company uses the self signed SSL certificate so the SSL connection had some problem. If same applies also for you, you can set the parameter again in gradle.properties file as follows:
org.gradle.jvmargs=-Djavax.net.ssl.trustStore="/usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts" -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.keyStorePassword=changeit
To be more clear you can click on "Show details" link in messages log in Android Studio. This log will be more helpful to decide what is the real problem.
This solution worked for me. I'm using Android Studio 3.1.2. Android Gradle plugin 3.1.2. Gradle 4.4. I have a library module with flavours such as trial and premium. As part of the process of migrating to the Android Gradle plugin 3.1.2 I added a flavour dimension of main to my library module's gradle build file. To correct the build error therefore in my app's build.gradle file I changed the following:
debugImplementation project(path: ':library', configuration: 'premiumDebug')
releaseImplementation project(path: ':library', configuration: 'premiumRelease')
became
implementation project(':library')
and I added the following line to my defaultConfig block: missingDimensionStrategy 'main', 'premium'

Implementing Swagger-codegen project - Error:(23, 17) Failed to resolve: junit:junit:4.12

Hi Im new to swagger and It was a while since I developed for Android - haven't understood all with the gradle files etc.
Im stuck with this problem with dependency to the JUnit 4.12
I have a project that I wan't to merge with a project created with a project generated with swagger-codegen
I have imported the source but now I'm stuck with getting to resolve Junit:2.14
Failed to resolve: junit:junit:4.12
I have tried to add it to gradlebuild diffrent ways and read some where that you sould add maven as repositiory. Have imported the pom.xml.
In the swagger-codegen project there's a file called build.sbt thats not in my project. Does it have anything to do with that file? Don't really understand why there should be yet another build file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.xxxxx.app.xxxxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
buildscript {
repositories {
jcenter()
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-gcm:7.8.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
androidTestCompile 'junit:junit:4.12'
}
Please use Swagger Codegen 2.2.0 (recently released) to generate the Android API client if you've not done so as the latest stable version generates Android API client with the Volley library (instead of HttpClient) by default (Android API client with HttpClient is no longer actively maintained).
You may also find this FAQ useful: https://github.com/swagger-api/swagger-codegen/wiki/FAQ#how-can-i-generate-an-android-sdk
About your question on the build.sbt file, that's used by another build tool called sbt, mainly used by Scala.
Do you even need junit?
If so, then I think the correct line of Gradle is this (drop the android piece of the compile)
testCompile 'junit:junit:4.12'
You have the repositories block for the buildscript but you need one for the dependencies:
repositories {
mavenCentral()
}
Junit 4.12 is hosted on MavenCentral here: https://mvnrepository.com/artifact/junit/junit.

Why does my code break going from Android Studio 1.3 to 2.0

I have a working app in 1.3 that breaks when I tried to "upgrade" to 2.0.
I tried code clean up as some have suggested , deleted the R file and recreated as others have suggested. This is the new error that is not present in 1.3 but shows up in 2.0 .
java.lang.ClassCastException: android.support.v7.widget.CardView cannot be cast to android.widget.ListView
Any thoughts that you may have so I can use 2.0 would be appreciated. For now I'm sticking with what works.
My list view is in a navigation drawer fragment. There are no cardviews anywhere associated. I have cards only in a recycler in another fragment.
For reference if it matters here's a piece of my build gradle for project and module
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath "io.realm:realm-gradle-plugin:0.88.2"
classpath 'com.google.gms:google-services:2.0.0-beta6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
// from build module
minSdkVersion 20
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.googlecode.java-diff-utils:diffutils:1.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile'com.google.android.gms:play-services-drive:8.4.0'
compile 'com.google.android.gms:play-services-auth:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
Ok, I found a solution: I upgraded my project settings to gradle version 2.10. I was at 2.4. I also changed gradle build to 2.1, I was at 2.0. After making these changes it compiles and runs nicely in Studio 2.0.
My take away lesson is be careful not to assume that when your code breaks that you are the cause. It may just be an artifact of an environment change or "upgrade".

Android Studio: deleting com.facebook.android package from build

I imported an Eclipse project in Android Studio. It uses the facebook SDK. In order to import it, I had to make sure the FacebookSDK folder was in the project path. The import was successful and I was able to do a build and there were no errors. However, when I try to run the app in the simulator I get the following error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/facebook/AccessToken$SerializationProxyV1;
From my research, this points to the fact that the com.facebook.android package resides in 2 places: in my project and in the FacebookSDK module, which is a dependency. To resolve this, my research indicates that I need to remove the package from my project and leave it in the FacebookSDK module.
I tried doing this in Android Studio by deleting the package from the Build folder (build\generated\source\r\debug\com.facebook.android). However, when I rebuild the project, it regenerates the package. So I decided to delete the package from Finder outside of Android Studio. But the same thing happens when I run a rebuild.
Please let me know what I am doing wrong, or if there is some way to exclude this package from the build, other than removing it.
By the way, in order to exclude the package from the build, I tried putting this in my project's build.gradle (which I found in an answer on stackoverflow), but the error still occurred:
configurations {
all*.exclude group: 'com.facebook.android'
}
Here's my gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId 'org.bicsi.fall2015'
minSdkVersion 14
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
configurations {
all*.exclude group: 'com.facebook.android'
}
dependencies {
compile project(':facebookSDK')
compile 'com.android.support:support-v4:19.1.0'
compile files('libs/Parse-1.3.8.jar')
compile files('libs/PushIOManager.jar')
compile files('libs/crittercism_v4_3_0_sdkonly.jar')
compile files('libs/facebooksdk.jar')
compile files('libs/httpclient-4.0.1.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/stackmob-android-sdk-1.3.5.jar')
compile files('libs/twitter4j-core-3.0.5.jar')
}
Your issue is here:
compile project(':facebookSDK')
compile files('libs/facebooksdk.jar')
You are using the same library (may be with different version) twice.
Remove the jar from your dependency.
Also, using Android Studio and the gradle system I suggest you removing your module locally and using
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
instead of compile project(':facebookSDK')
I would recommend you to place your 'gradle.build' file, showing the dependencies part, so it would be easier to help you.
From your explanation, you are importing twice the facebook module, from the imported module and from your own build, right?
Using compile project to include module and also getting it from maven repository. Maybe something like this?
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile project(':my_project_that_contains_facebook')
}
If thats the case, you can just do the following
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile (project(':my_project_that_contains_facebook')) {
exclude module: 'com.facebook.android'
}
}

Categories

Resources