0

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}
 }
Frank Zickert
  • 63
  • 1
  • 5
  • Do you use Proguard? Show your dependencies configuration for the other project. – tomrozb Jan 04 '15 at 08:03
  • I use proguard in the way you can see above in the edited section – Frank Zickert Jan 04 '15 at 15:51
  • This class may be stripped by Proguard, but I see you have `runProguard false` so it should not be a problem. I think your dependencies import may be wrong. You should try with package name of the endpoint classes instead of aar of the library app. Remember that generated cloud endpoints are located in the local maven repository. For Linux it's by default `.m2`. Your import my look like this: `compile 'package-name-of-your-endpoint:endpoint-name:version'` – tomrozb Jan 05 '15 at 06:49
  • where would I get the Version of my enpoint from? Since it is not an Android-module, it does not have the Android section in the gradle-file. – Frank Zickert Jan 07 '15 at 20:46
  • You can use `+` if you don't know the exact version name. `compile 'package-name-of-your-endpoint:endpoint-name:+` means that the latest version will be used – tomrozb Jan 08 '15 at 07:09
  • Unfortunately, this didn't work either. Anyway, many thanks! I really appreciate you helping me! I did found a (hackish) solution... – Frank Zickert Jan 11 '15 at 14:38

1 Answers1

0

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}
Frank Zickert
  • 63
  • 1
  • 5