Aar file with dependency to Google-App-Engine Module

Question!

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}
 }


Answers

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}


This video can help you solving your question :)
By: admin