Hi Guys,
I'm working on converting a existing Eclipse project to Android Studio, to
be able to debug my C++ SDK more easily.
We already have it compiling with the Android NDK for well over a year
using a set of Android.mk files, but for this case, we want to be able to
embed the SDK in an Android app to test and debug.
I'm using Android Studio 1.5 beta and currently Gradle 2.6 and
gradle-experimental:0.3.0-alpha7 wrapper.
I also have a project in Android Studio already, in which I jammed all
sources together in 1 module, but the project is packed with symlinks and
is not really portable, and hard to setup for other developers.
So I decided to start over and build the project configuration from ground
up. I'm using a Android Library Module for the SDK, which is used by the
Android Application module (test app).
The SDK module consists of a C++ core, with a JNI and Java wrapper around
it.
The module compiles and works fine - all output is nicely generated into an
AAR file in build/outputs/aar/
My issue is that when I try to compile the app, it fails, saying that my
SDK packages do not exist.
My app gradle files looks like this:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 19
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "com.mycompany.myapp"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 19
versionCode = 1
versionName = "1.0"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
debug {
debuggable = true
ndk.with {
debuggable = true
}
}
}
android.sources {
main {
java {
source {
srcDirs += 'src'
}
}
}
}
}
dependencies {
compile project(':sdk')
compile project(':sdk-testing')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:appcompat-v7:19.1.0'
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
My SDK gradle files looks like this:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 19
buildToolsVersion = "23.0.1"
defaultConfig.with {
versionName = '1.0'
}
}
android.ndk {
moduleName = "sdk"
toolchain = "gcc"
cppFlags += ["-D ANDROID_LOGCAT=1",
"-DGRADLE",
"-std=c++11",
"-frtti",
"-fexceptions",
"-I${projectDir}/../../../".toString(),
"-I${projectDir}/../../../src".toString(),
ldFlags += ["-Lsrc/main/jniLibs/armeabi"]
ldLibs += ["log", "atomic"]
stl = "c++_shared"
}
android.sources {
main {
// Java sources
java.source.srcDirs += '../../../external/src'
// local folder with symlinks, created by gradle task
:sdk:createLinks
jni.source.srcDirs += 'src/cpp'
}
}
android.productFlavors {
create("all") {
}
}
android.buildTypes {
release {
minifyEnabled = false
}
debug {
debuggable = true
ndk.with {
debuggable = true
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
task createLinks(type:Exec) {
workingDir 'scripts'
commandLine './createLinks.sh'
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'preBuild') {
task.dependsOn createLinks
}
}
I also have another pure Java module in my project, called sdk-testing,
which works fine when I add the dependency "compile project('sdk-testing')"
There is a way how I can get it to work:
I first let gradle build the SDK, and then manually copy the AAR file to
'app/libs', and add the following to the app build.gradle file:
repositories {
flatDir {
dirs 'libs'
}
}
And add the dependency:
compile(name:'sdk-all-debug', ext:'aar')
This is of course very inconvenient, because every time I change the SDK, I
need to recompile the SDK, copy it, and then copile the app, instead of
just using the 'Run App' or 'Debug App' buttons.
Is there anyone who has experienced this before? Am I forgetting something, or
using a wrong command?
Any help is appreciated :)
Kind Regards,
Maurice
--
You received this message because you are subscribed to the Google Groups
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.