3

I am trying to build an app which is composed out of separate library projects.

To do this, I'm trying to make a proof of concept which is supposed to be as following:
enter image description here

I tried to keep the project as simple as possible. The projects contents do not matter!
All that matters is the dependencies between the projects!

The result should be that MainProject will print out Something Another String!

I have tried all from .JAR files to .AAR files, but the best I got was
with the dependency in red. I added the StringExtender.aar file to StringReturner, and then the StringReturner.aar file to the MainProject.

When I do this I get the following Exception:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/erik/stringextender/StringExtender;

What is the right way to setup a simple proof of concept like this? I can't seem to find anything related to a library project having a dependency. It's all 1 level deep!

Any help is welcome!

EDIT SHOWING GRADLE BUILD FILES
StringReturner:

apply plugin: 'com.android.library' android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile project(':StringExtender-lib-debug') } 

MainProject:

apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { applicationId "com.example.erik.erikpoc10" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:design:23.2.1' compile project(':StringReturnerLib-debug') } 
1
  • @MsYvetteǝʇʇǝʌʎsW Done! Commented Apr 4, 2016 at 15:01

1 Answer 1

2
+50

Use the following tutorial - Creating libraries for Android applications

See a working example project on my Github

The most important steps taken were:

  • 8.3. Create library module.
  • 8.6. Define dependency to the library project.

Do not forget to import the library class you want to use, for example:
In MainProject: import com.example.stringreturner.StringReturner. In StringReturner: import com.example.stringreturner.StringExtender.

The info below is based on the image you provided:

The library methods are not static so don't forget to make an actual object. So StringReturner should make a StringExtender object, And MainProject should make a StringReturner object first!

And finally, I think it's a typo but both libraries have the class StringReturner. This will not work in the StringReturner library for obvious reasons.

I should also note that I used Android Studio 2.0 and I did not touch .JAR files nor .AAR files. I merely created two library modules and one app. Then configured the Project Structure -> Dependencies by adding Module Dependencies.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.