Reputation: 1156
Since two days I am trying to figure out how to get the following to compile.
I have an android studio project called "Margin", which shall use the library "hbci4java", which in turn uses the project "cryptalgs4java".
The directory structure is as follows:
Margin
+-# app
| +-# build
| +-# libs
| | +-# hbci4java
| | +-# src
| | | +-# org/kapott/hbci
| | | | +-# manager
| | | | | +-- HBCIHandler.java
| | | | | +-- ...
| | | | +-- ...
| | | +-- ...
| | |
| | +-# thirdparty
| | | +-# cryptalgs4java
| | | +-# src
| | | +-- build.gradle
| | | +-- ...(other files)
| | |
| | +-- build.gradle
| | +-- settings.gradle
| |
| +-# src
| | +-+ main
| | | +-# java
| | | | +-# de/bvs/margin
| | | | +-# activities
| | | | | +-- MainActivity.java
| | | | | +-- ...
| | | | + ...
| | | |
| | | +-- ...
| | +-- ...
| |
| +-- build.gradle
| +-- ...
|
+-# build
+-# gradle
+-- build.gradle
+-- gradle.properties
+-- settings.gradle
+-- ...
The app containing MainActivity compiled well before I added the libs directory structure, and it still does, as long as I don't tell android studio anything about this directory. However, I want to use the hbci4java project within my project. Let's say, I want to create a HBCIHandler object within my Mainactivity.
I know, I have to tell the build system, that it shall use the hbci4java library. But i'm overhelmed by the different gradle files:
I understand that Margin/app/libs/hbci4java/thirdparty/cryptalgs4java/buid.gradle is used to build the cryptalgs4java, when standing alone. It contains the following:
apply plugin: 'java'
repositories {
mavenCentral()
}
sourceCompatibility = 1.5
compileJava.options.encoding = 'ISO-8859-1'
version = '2.5.13-SNAPSHOT'
sourceSets{
main {
java {
srcDir 'src/java'
}
output.classesDir 'classes'
}
}
Also Margin/app/libs/hbci4java/build.gradle and Margin/app/libs/hbci4java/settings.gradle seem to be clear to me, when just building the hbci4java project:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile project(':thirdparty/cryptalgs4java')
testCompile group: 'junit', name: 'junit', version: '4.+'
}
sourceCompatibility = 1.5
compileJava.options.encoding = 'ISO-8859-1'
compileTestJava.options.encoding = 'ISO-8859-1'
version = '2.5.13-SNAPSHOT'
sourceSets{
main {
java {
srcDir 'src'
}
output.classesDir 'classes'
}
test {
java {
srcDirs 'test'
}
}
}
settings:
include 'thirdparty/cryptalgs4java'
But I'm totally not sure how the building of the android project works, and how I can make it aware of the library project.
Here are the contents of the remaining gradle files:
Margin/app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "de.bvs.margin.margin"
minSdkVersion 19
targetSdkVersion 22
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:22.2.0'
}
Margin/build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
and Margin/settings.gradle:
include ':app'
I tried several locations to place the libs folder and also tried to mention it in the different gradle files, with no success so far.
I hope, anybody can help me figure out, how to use the libs and make android studio aware of them.
best wishes, Stephan
Upvotes: 1
Views: 177
Reputation: 1156
After fiddeling a bit more, i found out that the following does the trick:
add the following lines to Margin/settings.gradle:
include ':app:libs:hbci4java', ':thirdparty/cryptalgs4java'
project(':thirdparty/cryptalgs4java').projectDir = new File('app/libs/hbci4java/thirdparty/cryptalgs4java')
add
compile project(':app:libs:hbci4java')
to the dependencies section in Margin/app/build.gradle
Now, gradle is able to resync and android studio will allow to add the project hbci4java as dependency in Margin.
Upvotes: 1