Aar file with dependency to Google-App-Engine Module - android

My (Android Studio) project has two modules: an Android-Library (app) Module and a Google Backend Module. The app module accesses the backend. in my gradle dependencies (app) I have:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':Backend', configuration: 'android-endpoints')
compile ('com.google.android.gms:play-services-wearable:6.1.71') {
exclude module: 'support-v4'
}
I want to use the app library in other projects, so I tried a) exporting it to a aar-library and b) exporting it into a jar-library. It works during compile time. I can use all classes of the app-module. But when running this app, it gives me an error, that it does not find the class that is the Interface between app and backend modules (as part of the backend).
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/cluedup/voicecontrols/backend/apiVoiceForm/model/VoiceFormBean;
Does anybody have an idea of how I can get this to work?
EDIT: Here are the complete gradle-files:
Library-App:
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.cluedup.voicecontrols"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs', '../backend/libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':Backend', configuration: 'android-endpoints')
compile ('com.google.android.gms:play-services-wearable:6.1.71') {
exclude module: 'support-v4'
}
}
Importing app
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.cluedup.voicecontrols.sample"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.google.android.gms:play-services-wearable:6.1.71') {exclude module: 'support-v4'}
compile(name:'app-debug', ext:'aar'){transitive=true}
}

Here is what works for me - it seems like a hack for me, though! So if someone has a better solution, I'll still would be glad to hear about
Step 1: Create a jar of the backend-module. Actually, the jar of the backend is produced as byproduct when trying to publish the whole app in the sonatype central repository. I followed this example (http://gmariotti.blogspot.de/2013/09/publish-aar-file-to-maven-central-with.html) to prepare for the upload.
As a result, I found a jar-file of the backend in the ../backend/build/libs Directory.
Step 2: Remove the dependency of the app to the backend-module and replace it with a dependency to the created jar-file
// DO NOT USE compile project(path: ':Backend', configuration: 'android-endpoints')
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}
Step 3: create the aar-file of the app with gradlew assemble
Step 4: add the jar of the backend and the aar of the app as dependencies in the importing Project
compile(name:'app', ext:'aar'){transitive=true}
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}

Related

Android Studio can't resolve Espresso 3.0.0

According to the Android Espresso documentation to date:
Add Espresso dependencies
To add Espresso dependencies to your project, complete the following steps:
Open your app’s build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle.
Add the following lines inside dependencies:
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
androidTestCompile 'com.android.support.test:runner:1.0.0'
I created a new project and the generated app/gradle file was like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 24
targetSdkVersion 26
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'
})
compile 'com.android.support:appcompat-v7:26.+'
testCompile 'junit:junit:4.12'
}
When I change it to the following:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 24
targetSdkVersion 26
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'])
compile 'com.android.support:appcompat-v7:26.+'
testCompile 'junit:junit:4.12'
// App's dependencies, including test
compile 'com.android.support:support-annotations:22.2.0'
// Testing-only dependencies
androidTestCompile 'com.android.support.test:runner:1.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
}
I get the following errors:
Error:(29, 24) Failed to resolve: com.android.support.test:runner:1.0.0
    Install Repository and sync project
Error:(30, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.0
    Install Repository and sync project
I have tried clicking on the "Install repository and sync project" link but nothing happens. I have also tried looking through the SDK manager, but I can't really see anything.
As the solution from comment is solving the problem I am adding it as an answer for others:
Be sure to add Google's maven link to main build.gradle file:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Simply,
Adding google() into allprojects > repositories will do the trick here...
allprojects {
repositories {
google()
jcenter()
}
}
you can downgrade the version, somehow sometimes the targeted version is unavailable from the repo.
use IDE-UI to select the latest version:
Right click on your project folder, select Open Module Settings
search for the package you want in the dependencies, for example
This way, you'll never get an un available version
(of course remember to set proper repo in build.gradle, too)
use these versions
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

Android NoClassDefFoundError for library's class inside a dependency

I created an Android library named "core" that use the Logger library (https://github.com/orhanobut/logger).
Here its build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
minSdkVersion 16
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'])
compile 'com.orhanobut:logger:1.15'
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}
Then I build a .aar of core library.
I add this library as a dependency into my application, by putting the .aarcore files in the libs folder.
That's the build.gradle of my application :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.package.test"
minSdkVersion 16
targetSdkVersion 25
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'com.mypackage:core:1.0#aar'
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'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:multidex:1.0.1'
}
As you can see I have multidex activated.
It compile just fine but at runtime, at the first call to Logger I get an exception:
stack=java.lang.NoClassDefFoundError: Failed resolution of: Lcom/orhanobut/logger/Logger;
Even if I set transitive = true
compile (com.mypackage:core:1.0#aar) {
transitive=true
}
it doesn't work.
Thank you !
I had to do a couple of things in concert to get it to work.
1) In your library project
Add the following to your project-level gradle file:
buildscript {
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
Be sure to use the right version of the plugin for your gradle version, check here.
Add the following to your module-level gradle file:
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.YourPackage'// Doesn't have to be github, just an example
Also in this file, make sure your dependencies (the ones you want to be transitive) use api instead of implementation if you are using Gradle 3.4+. If you are using a version of Gradle <3.4, compile is the way to go. Example:
dependencies {
api 'com.google.android.gms:play-services-location:15.0.1'
}
2) In your app project (which uses the library)
Add the following to your module-level gradle file:
dependencies {
implementation('com.github.YourPackage:yourRepo:version#aar') {
transitive=true
}
}
Add the following to you project-level gradle file (but this will depend on where your library is served from, for me it's jitpack):
allprojects {
repositories {
...
maven {
url 'https://jitpack.io'
credentials { username 'yourAuthKey' }// Only for private repositories
}
}
}
Note: You shouldn't add the auth key as a string in build.gradle, put it in a property in your gradle.properties file.
Note 2: JitPack allows you to use for example development-SNAPSHOT as a version number for a gradle dependency. Android Studio caches these dependencies and will not re-download it when you push to your development branch. To overcome this, use commit hashes as version numbers during development or clear (delete) the cache files, located on Windows at ~/.gradle/caches/modules-2/metadata-x.xx/descriptors/com.github.YourPackage/yourRepo. (Needles to say, I learned this the hard way).

How to fix duplicate entry ZipException in android?

I am using EBS payment gateway in my android application. EBS includes volley library in its folder. Also I use volley library for my project.So I get an exception like this.
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/android/volley/AuthFailureError.class
And below is my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
repositories {
mavenCentral()
}
configurations{
all*.exclude group: 'com.android.volley', module: 'toolbox'
}
defaultConfig {
applicationId "com.example.nivedha.rents"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile project(':EBS')
}
Help me out to fix this issue..
Do like this :
When you added com.mcxiaoke.volley:library-aar:1.0.0 your some of the dependencies got clashed
So, now what you have to do is
Search CTRL+SHIFT+N in android studio for the class AuthFailureError.class
See which jar contains this and remove it like below (This is just as an example/You have to figure out the duplicate class and manually remove it)
configurations{
all*.exclude module: 'toolbox'
}

AndroidStudio gradle sync : failed to resolve

I have new clear android app. I want to add volley to my app to make HTTP request. I am developing app with Android studio using Gradle. Here is screenshot for my app:
Ass you see i am going to add volley to my app adding this line of code com.mcxiaoke.volley:library-aar:1.0.0 to build.gradle file
I tried to add Retrofit too. But it gives same type of error: Failed to resolve: bla bla bla.
So i think in my situation gradle can not sync any other library different than com.android......
And i have tried add this lines of code to my build.gradle too. but nothing is changing
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
repositories {
mavenCentral()
}
}
Please advise
Edit: After comments added build.gradle files for project and for module.
Project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "domain.testgradle"
minSdkVersion 11
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:23.0.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
}
Volley is now published by the Android Open Source Project on jCenter:
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
You can use
com.mcxiaoke.volley:library-aar:1.0.1
Or its latest version (Not aar)
compile 'com.mcxiaoke.volley:library:1.0.19'
And set
buildToolsVersion "23.0.1"
and use
'com.google.code.gson:gson:2.3'
Add this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:+'
compile 'com.mcxiaoke.volley:library:1.0.19'
}

Android-studio unresolved dependency: android-maps-utils

I am using android-studio 0.6.1 and have all necessary google repositories installed in SDK manager: however when I try to build a project, gradle says about unresolved dependency:
Unresolved dependencies:
Error:com.google.maps.android:android-maps-utils:+
My build.gradle looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 12
targetSdkVersion 19
versionCode 1
versionName '0.1'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.maps.android:android-maps-utils:+'
}
I know I can just import all necessary instruments in library folder, however I would like to resolve this problem. Do you have any suggestions?
EDIT:
Found a way to solve it:
Looks like the problem was in absense of
compile 'com.android.support:support-v4:19.0.1'
in build.gradle, also I had to empty 'library' folder and delete the line in order to avoid 'duplicate packages' problem with support libraries:
compile project(':library')
So my final build.gradle file looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 12
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
repositories {
mavenCentral()
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.google.android.gms:play-services:4.4+'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
The error is
Unresolved dependencies:
Error:com.google.maps.android:android-maps-utils:+
I'd say double check that you've got the dependency correctly defined. Looking at the Map Utils website leads me to believe you might want to declare the dependency with a version.
Replace
compile 'com.google.maps.android:android-maps-utils:+'
to
compile 'com.google.maps.android:android-maps-utils:0.3+'
Do a Gradle Sync and everything should build correctly.
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Try to replace this:
compile 'com.google.maps.android:android-maps-utils:0.3+'
with this
compile 'com.google.android.gms:play-services-maps:9.4.0'

Categories

Resources