I've managed to setup a java test in my project however I've fallen into two different pitfalls.
1) I make a Java module, I can run it and do some arbitrary tests but since my Viewmodels/presenters/models are all in my Android project it means I cannot get the objects. That's a pretty big problem, I suppose an alternative would be to create a module for just the Presenters or ViewModels + Models.. but that seems bad
2) I make a folder under src/test/java/... however when I'm in there and try to compile, due to the lambda expressions in my project I end up getting weird compilation errors due to retrolambda.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.lang.invoke.MethodType not found
How do I go about setting up my gradle to testCompile in a way where Retrolambda isn't messing things up? Below is my gradle for the project
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.3"
}
}
apply plugin: "net.ltgt.apt"
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "io.patrykpoborca.cleanarchitecture"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
encoding "UTF-8"
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
dependencies {
apt 'com.google.dagger:dagger-compiler:2.0'
testApt 'com.google.dagger:dagger-compiler:2.0'
//needed to resolve compilation errors, thanks to tutplus.org for finding the dependency
// http://stackoverflow.com/questions/27036933/how-to-set-up-dagger-dependency-injection-from-scratch-in-android-project
//test compiles
androidTestApt 'com.google.dagger:dagger-compiler:2.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.dagger:dagger:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'com.jakewharton:butterknife:7.0.1'
androidTestCompile 'com.google.dagger:dagger:2.0'
testCompile 'com.google.dagger:dagger:2.0'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.3'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'org.mockito:mockito-core:1.+'
androidTestCompile('com.android.support.test:runner:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
}
}
P.s. does anyone know how to set a Java module's JavaVersion? In my java module Lambda's compiled despite being told that the version of java was wrong... really weird, here's the gradle of the java module. Thanks!
apply plugin: 'java'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.3"
}
}
apply plugin: "net.ltgt.apt"
dependencies {
apt 'com.google.dagger:dagger-compiler:2.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'com.google.dagger:dagger:2.0'
testCompile project(':app')
}
Related
I am attempting to generate an apk to install to a device. I was able to do this with the same project prior to Android Studio version 3.0.0. I cannot post any error logs because the apk generates successfully, but when I try to install it on a device I get "App not installed", "File appears to be corrupt". I have been through a number of other threads to try and fix this but nothing has worked so far.
The previous version on the phone has been uninstalled.
Both Signed and unsigned have been tried.
Instant run has been disabled.
The apk has failed to install on at least 3 different devices.
I have tried downgrading my com.android.tools.build:gradle
Any help would be greatly appreciated, I feel like I've tried everything.
build.gradle (app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.will3596.mobileapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}
dependencies {
implementation 'com.android.support:support-vector-drawable:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design: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:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-core:11.6.2'
compile 'com.google.firebase:firebase-auth:11.6.2'
compile 'com.google.firebase:firebase-database:11.6.2'
compile 'com.google.android.gms:play-services-maps:11.6.2'
compile 'com.google.android.gms:play-services-location:11.6.2'
compile 'com.google.firebase:firebase-storage:11.6.2'
compile 'com.android.support:palette-v7:26.+'
compile 'com.android.support:customtabs:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support:cardview-v7:26.+'
compile 'com.android.support:mediarouter-v7:26.+'
compile 'com.android.support:multidex:1.0.2'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.maps.android:android-maps-utils:0.4+'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.7.22'
androidTestCompile 'com.android.support:support-annotations:24.0.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
apply plugin: 'com.google.gms.google-services'
build.gradle (project):
// 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.1.1'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Let me know what else I can post to help get a solution.
Steps to generate debug apk from 3.0.0+
Build->Build APK(s).
I found the answer in another thread somewhere. In my android manifest, I had testOnly="true", set to false and it fixed.
I am getting the following error when trying to compile the project:
error: package lombok does not exist
And others stating that all the annotations from it can't be found.
I don't see errors in code before compiling and I didn't have this error while I was using Android Studio 3 RC1.
Here are my gradle scripts:
Project level:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App module level:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.mk.forum"
minSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile project (':util')
compile project (':forum_core')
compileOnly 'org.projectlombok:lombok:1.16.18'
annotationProcessor 'org.projectlombok:lombok:1.16.18'
compile group: 'com.github.javafaker', name: 'javafaker', version: '0.13'
}
I've got modules too, but I think it isn't important.
I hope it is because of compileOnly annotation. Here is the doc:
blog.gradle.org/introducing-compile-only-dependencies
Dependencies required at compile time but never required at runtime, such as source-only annotations or annotation processors;
Dependencies required at compile time but required at runtime only when using certain features, a.k.a. optional dependencies;
Dependencies whose API is required at compile time but whose implementation is to be provided by a consuming library, application
or runtime environment.
It might be related to jdk9. I know that the combination of IntelliJ, lombok 1.16.18 and jdk9 currently doesn't work. But that does not explain your error message. We expect that we can release 1.16.20 within a few days (maybe tonight) that addresses this problem.
Disclosure: I am a lombok developer.
Why i ask, on every solution i jsut have information that apply plugin on bottom, but i have this, but this not work on my side. I try to do this on 5 hours. Im got error after trying to implement google maps on my application. Maybe i miss something in code? I dont know where is problem, so please guys look at code, maybe you will have any idea whats wrong. Thanks fro advice.
This is error:
Error:Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.company.andrzej.rolki.wroclawnarolkach"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
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'
})
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'
}
apply plugin: 'com.google.gms.google-services'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-ads:10.2.1'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.android.gms:play-services-maps:10.2.1'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.google.firebase:firebase-crash:10.2.1'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.android.gms:play-services-analytics:10.2.1'
compile 'com.google.android.gms:play-services-gcm:10.2.1'
compile 'com.google.android.gms:play-services-location:10.2.1'
}
apply plugin: 'com.google.gms.google-services'
And project
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
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
}
Remove apply plugin: 'com.google.gms.google-services' line from dependencies block. You wrote it twice.
Everything was working fine, but after adding this to my android project error building apk started.Here is the error and dependency
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/crashlytics/android/answers/shim/R.class
compile('io.branch.sdk.android:library:2.6.0#aar') {
transitive = true;
exclude module: 'answers-shim'
}
tried excluding it also but error persists.
Here is my full gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://dl.bintray.com/hani-momanii/maven"}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 19
targetSdkVersion 25
multiDexEnabled true
versionCode 1
versionName "1.0"
resConfigs "en_US", "hi_IN"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.digits.sdk.android:digits:2.0.6#aar') {
transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics:2.6.7#aar') {
transitive = true;
}
compile('io.fabric.sdk.android:fabric:1.3.10#aar') {
transitive = true;
}
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:support-annotations:25.3.1'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.android.gms:play-services-location:10.2.1'
compile 'com.google.android.gms:play-services-places:10.2.1'
compile 'com.amazonaws:aws-android-sdk-core:2.2.+'
compile 'com.amazonaws:aws-android-sdk-s3:2.2.+'
compile 'com.amazonaws:aws-android-sdk-ddb:2.2.+'
compile 'com.amazonaws:aws-android-sdk-lambda:2.2.+'
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
compile 'com.google.firebase:firebase-crash:10.2.1'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.google.firebase:firebase-storage:10.2.1'
compile 'com.google.firebase:firebase-appindexing:10.2.1'
compile 'com.github.clans:fab:1.6.4'
compile 'com.amazonaws:aws-android-sdk-cognito:2.3.9'
compile 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile('io.branch.sdk.android:library:2.6.0#aar') {
transitive = true;
exclude module: 'answers-shim'
}
}
apply plugin: 'com.google.gms.google-services'
If i add the exclude statement to branch and digits then while entering the app it crashes,if added exclude to crashlytics the error persists.But without adding branch everything works perfect no error during apk build too.
I was struggling with this all day today as well. What ended up fixing it for me was rolling back branch to 2.5.9. There obviously seems to be something wrong with the new 2.6.0 release.
Another note for branch I don't have the transitive aar include so it's just
compile ('io.branch.sdk.android:library:2.5.9') {
exclude module: 'answers-shim';
}
Fixed the the issue when removed transitive = true from the dependency
compile('io.branch.sdk.android:library:2.6.0#aar') {
exclude module: 'answers-shim'
}
For those who want to use the latest version of branch.io, you have to add the following lines in your proguard file.
-dontwarn com.crashlytics.android.answers.shim.**
-dontwarn com.google.firebase.appindexing.**
-dontwarn com.android.installreferrer.api.**
With this change exclude module: answers-shim is not required in the gradle file.
In my Android app I'm trying to implement ORM for SQLite database for existing db. I've tried to implement activeandroid and DBFlow, but Android studio shows error that it can't recognize method. Here's how it shows when I try to use DBFlow ORM and similarly for activeandroid it doesn't recognize methods in annotations. The red in below screenshot is error. It says it can't recognize method databaseName and also constant PRIMARY_KEY doesn't exist.
Here's project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And here's app: build.gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myapplication"
minSdkVersion 16
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'org.immutables:gson:2.0.6'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup:otto:1.3.8'
compile 'com.airbnb:deeplinkdispatch:1.5.0'
apt 'com.airbnb:deeplinkdispatch-processor:1.5.0'
apt 'com.github.Raizlabs.DBFlow:dbflow-processor:3.0.0-beta1'
compile "com.github.Raizlabs.DBFlow:dbflow-core:3.0.0-beta1"
compile "com.github.Raizlabs.DBFlow:dbflow:3.0.0-beta1"
}