Android Studio doesn't compile test classes for Java library modules during Make Project - android-studio

I have a multi-project Gradle build in Android Studio 2.2.3, containing Java library (core and codegen) and Android library (android) modules. Make Project shows executed tasks in Gradle console:
Executing tasks: [:android:generateDebugSources, :android:generateDebugAndroidTestSources, :android:mockableAndroidJar, :android:prepareDebugUnitTestDependencies, :android:compileDebugSources, :android:compileDebugAndroidTestSources, :android:compileDebugUnitTestSources, :codegen:compileJava, :core:compileJava]
But compileJava compiles only the main classpath, not tests, and testClasses tasks for core and codegen are not listed. On the other hand, ./gradlew build does run testClasses.
How can I make Android Studio compile tests for Java library modules as well?
settings.gradle:
include 'core'
include 'codegen'
include 'android'
Main build.gradle:
buildscript {
repositories {
maven {
url "http://10.122.85.159:9081/nexus/content/groups/public"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url "http://10.122.85.159:9081/nexus/content/groups/public"
}
}
}
dependencies {
}
core/build.gradle:
apply plugin: 'java'
version = '1.0.0'
sourceCompatibility = '1.7'
sourceSets {
generated {
java {
srcDirs = ['src/generated/java']
}
}
}
test {
filter {
}
}
dependencies {
compile fileTree(dir: '../lib', include: '*.jar')
generatedCompile project(':core')
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile 'org.javatuples:javatuples:1.2'
}
codegen/build.gradle:
apply plugin: 'java'
dependencies {
compile project(':core')
compile group: 'com.squareup', name: 'javapoet', version: '1.8.0'
}
android/build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
minSdkVersion 24
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
disable 'OldTargetApi'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':core')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}

Related

Migrating to the New Places SDK Client

When I add in my gradle dependencies implementation 'com.google.android.libraries.places: places: 1.0.0'
I continue with the error: Java Compiler error: cannot access Hide
org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
Here is my list of dependencies:
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 26
buildToolsVersion '26.0.3'
defaultConfig {
applicationId 'com.test.pass'
minSdkVersion 17
targetSdkVersion 26
versionCode 13
versionName '1.0.3'
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
dexOptions {
javaMaxHeapSize '4g'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.+'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
})
compile('com.mikepenz:fastadapter:2.0.0#aar') {
transitive = true
}
compile 'com.afollestad.material-dialogs:core:0.9.0.0'
compile 'com.mikepenz:iconics-core:2.8.1#aar'
compile 'com.mikepenz:fontawesome-typeface:4.6.0.2#aar'
compile('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
exclude module: 'support-v4'
}
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:support-vector-drawable:26.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.guava:guava:19.0'
compile 'com.dmitrymalkovich.android:material-design-dimens:1.4'
compile 'com.ogaclejapan.smarttablayout:library:1.6.1#aar'
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.6.1#aar'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'me.relex:circleindicator:1.2.2#aar'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.google.firebase:firebase-core:12.0.1'
compile 'com.google.firebase:firebase-messaging:12.0.1'
compile 'com.mobsandgeeks:android-saripaar:2.0.3'
compile 'com.google.android.gms:play-services:12.0.1'
compile 'org.greenrobot:eventbus:3.1.0'
compile 'com.makeramen:roundedimageview:2.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'com.github.siyamed:android-shape-imageview:0.9.3'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.balysv:material-ripple:1.0.2'
}
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
dependencies {
implementation 'com.google.android.libraries.places:places:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
and here is my project level gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'io.realm:realm-gradle-plugin:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
// maven {
// url 'https://maven.google.com/'
// name 'Google'
// }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Add this in your app gradle file under dependencies:
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
this is not my solution, I got it from other guy from SO, but can't find that question. I will add the link to that post later.
Edited: Original Answer

Android studio APK buil error transformClassesWithJarMergingForDebug

I'm trying to build APK, but there is an error when I try to make it.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/gcm/PendingCallback.class
Following is my build.gradle(Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "jordan.personicle"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
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'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/ajt-2.9.jar', 'libs/javaml-0.1.7.jar')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.firebase:firebase-jobdispatcher:0.6.0'
compile 'org.jsoup:jsoup:1.7.3'
compile 'com.android.support:multidex:1.0.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is my build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I think there is no duplication for gcm. What is the problem?
Thanks,
Make sure you use the same version in all your google play services libs:
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'
See https://stackoverflow.com/a/42610163/1370087

Error:(20,0)Could not find method compile() for arguments [file collection]

Below are my gradle files..
so here is the error which i get when i sync the project:-Error:(20, 0) Could not find method compile() for arguments [file collection] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File
Following is my app gradle...
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.sinch.workshopskeleton"
minSdkVersion 9
targetSdkVersion 20
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:20.0.+'
compile files('libs/sinch-android-rtc-3.3.5.jar')
}
Following is my project gradle
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
dependencies {
compile files('app/libs/sinch-android-rtc-3.11.1.jar')
}
Remove below lines from your project's build gradle and it will work fine.
You can add this in your app level build gradle.
dependencies {
compile files('app/libs/sinch-android-rtc-3.11.1.jar')
}

I can not add a dependency in Android Studio

I'm new in Android Studio and i want to add dependency to custom view (https://github.com/glomadrian/dashed-circular-progress) in my project. I downloaded *.arr file from Maven repository and imported it like a AAR module. But i can't compile my project because there are some exceptions with this custom view: ClassNotFoundException. Could someone explain me step by step how to correctly add dependencies from maven rep? or there are some problems with this DashedCircularProgress.aar? Thanks.
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.ahryk94gmail.mibandsdk"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile files('libs/gson-2.6.2.jar')
compile 'com.github.glomadrian:DashedCircularProgress:1.0#aar'
}
As mentioned in the project description you have to add the following code to build.gradle:
repositories {
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
}
dependencies {
compile 'com.github.glomadrian:DashedCircularProgress:1.0#aar'
}
UPDATE:
Also you can use jitpack.io and download the dependency right from GitHub.
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.github.glomadrian:dashed-circular-progress:59d245a'
}

Plugin with id 'crashlytics' not found issue with Android studio latest plugin

For the following gradle build configuration, I am facing Error:(11, 0) Plugin with id 'crashlytics' not found error.
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
apply plugin: 'hugo'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.wiznsystems.android"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/smartconfiglib.jar')
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.2.42'
compile 'com.jakewharton.hugo:hugo-runtime:1.1.0'
compile 'com.squareup.retrofit:retrofit:1.+'
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.jakewharton:butterknife:5.+'
compile 'de.greenrobot:eventbus:2.2.1'
compile 'fr.avianey:facebook-android-api:+#aar'
compile 'com.squareup.picasso:picasso:2.+'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.4'
compile project(':apptentiveandroidsdk')
}
Am I doing something wrong? or Is there any workaround for making it build?
I had the same issue. What I ended up doing was putting the order of the commands inline with what Crashlytics provided. I had something similar to yours and it didn't work. Once it changed it to the exact order of there docs it worked. Here is what mine looks like now. Hope this helps.
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.0.+'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.joanzapata.android:android-iconify:1.0.6'
compile 'com.github.hotchemi:android-rate:0.3.1'
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.github.satyan:sugar:1.3'
compile 'com.crashlytics.android:crashlytics:1.+'
}
android {
compileSdkVersion 19
buildToolsVersion "20"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Try informing the classpath dependency:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
After battling with this error for hours, I ended up deleting the ".gradle" folder on my home directory, and the issue vanished! So, if you are getting this issue, try deleting the .gradle folder first, then rebuild your project.

Resources