I'm compiling an Android library (.aar) as a module that contains some native code and requires some libraries. Here's the build.gradle:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
//
// NOTE: change the application ID to match the play console linked application.
//
applicationId = "org.anima.mrubybridge"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 18
}
}
android.ndk {
moduleName = "mrubybridge"
CFlags += "-I/home/dragos/Downloads/mruby-1.1.0/include"
CFlags += "-I/home/dragos/Downloads/mruby-1.1.0/include"
ldLibs += ["mruby"]
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
create ("arm7") {
ndk.abiFilters += "armeabi-v7a"
ndk.ldFlags += "-L/home/dragos/Downloads/mruby-1.1.0/build/armeabi-v7a/lib"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
This compiles everything (I checked the .class and .so files), but the .aar archives are almost empty with no classes or dynamic libraries. (about 2.3KB)
In the second module, I add this as a dependency:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
//
// NOTE: change the application ID to match the play console linked application.
//
applicationId = "com.example.dragos.mrubytest"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 18
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
}
dependencies {
compile project(':mrubybridge')
compile fileTree(dir: 'libs', include: ['*.jar'])
// testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
But when I try to add the Java classes from the other module, I get: Error:(12, 29) error: package org.anima.mrubybridge does not exist, most probably because they're not in the .aar.
I've added the module as a dependency (compile project(':mrubybridge')), but it doesn't really help.
I encountered the same issue. This answer solved it for me:
#Radix
"Put the .aar file in the app libs directory (create it if needed), then, add the following code in your app build.gradle":
dependencies {
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
repositories{
flatDir{
dirs 'libs'
}
}
Adding local .aar files to Gradle build using "flatDirs" is not working
Related
I'm new in NDK .and try to setup Integration with NDk .But after research through many sites ,i could not solved my problem. Here is build.gradle file
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
}
android.ndk {
moduleName "native"
}
defaultConfig.with {
applicationId "app.com.jnitester"
minSdkVersion.apiLevel 15
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
buildConfigFields {
create() {
type = "int"
name = "VALUE"
value = "1"
}
}
}
/* android.ndk {
moduleName = "native"
}*/
android.buildTypes {
release {
minifyEnabled false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
create("flavor1") {
applicationId "com.app"
}
}
android.sources {
main {
jni {
source {
srcDir 'src'
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
my classpath is:
classpath 'com.android.tools.build:gradle-experimental:0.4.0'
we get error like that:
Error:(18, 0) No signature of method: org.gradle.model.dsl.internal.NonTransformedModelDslBacking.applicationId() is applicable for argument types: (java.lang.String) values: [app.com.jnitester]
Open File
when i put buildTypes,productFlavours,sources inside android{} then it gives Errors like that:
Error:(4, 1) A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> Could not find method compileSdkVersion() for arguments [23] on project ':app'.
may be this question be duplicate but we couldn't find the solution yet .
Your help would save my time. Any Help would be appreciated in Advanced.
try adding '=' char. e.g.
compileSdkVersion 23
change to
compileSdkVersion = 23
I'm trying to use Experimental Gradle Plugin for my NDK projects, but it do not compile ndk. Everything looks fine - Android Studio understands my C code, can jump from Java to native and so on, but when i run "Build", step of compiling ndk is skipped - i see no tasks like "compileNdk".
When I list all available tasks by
gradlew tasks
there is no taks like "compileNdk" also. "Libs" folder are empty too, so when I try to call native method, app crash with "UnsatisfiedLinkError".
So what am i missing? How to tell gradle to compile NDK?
My config is:
root build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.3.0-alpha5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
module build.gradle:
apply plugin: 'com.android.model.application'
model
{
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "com.kaspersky.experimentalcpp"
minSdkVersion.apiLevel = 14
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
}
android.buildTypes {
debug {
ndk.with {
debuggable = true
}
}
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.sources {
main {
jni {
source {
srcDirs 'src/main/jni'
}
}
}
}
android.ndk {
moduleName = "test_experimental"
stl = "stlport_static"
cppFlags += "-Isrc/main/jni".toString()
ldLibs += ["log"]
ldLibs += ["android"]
}
android.productFlavors {
create("arm") {
ndk.abiFilters += "armeabi"
}
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
create("fat")
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
}
I'm using Android Studio 1.4.1 on Windows 7. ndk.dir points to "ndk-bundle" folder which was downloaded by AS.
Any help appreciated!
So after some research I figured out that my libs actually compiles, they just puts not in the "libs" folder, but in "build/intermediates/binaries/...". I dump result .so and figured that my JNI methods was not in there. The reason was that my JNI methods was declared in .h file. After renaming .h to .cpp all works fine (except debugging). Maybe it will help somebody else!
I am trying to use the ffmpeg libraries with Android NDK in the experimental plugin.
I am attempting to compile this example:
https://github.com/roman10/android-ffmpeg-tutorial/blob/master/android-ffmpeg-tutorial01/jni/tutorial01.c
My problem is that the header files are not being found by the compiler:
Error:(13, 32) libavcodec/avcodec.h: No such file or directory
I added flags to build.grade:
cppFlags += "-ilibavcodec -ilibavutil -ilibavformat -ilibswscale"
ldFlags += "-llibavcodec -llibavutil -llibavformat -llibswscale"
Which seems to keep lint happy, but not the compiler. (Not sure if I have done this right?)
I Have added the header files to the /jni folder:
And build.grade looks like this:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "roman10.tutorial.android_ffmpeg_tutorial01"
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 23
}
}
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.ndk {
moduleName = "tutorial01"
ldLibs += ["android","log","jnigraphics","z"]
cppFlags += "-ilibavcodec -ilibavutil -ilibavformat -ilibswscale"
ldFlags += "-llibavcodec -llibavutil -llibavformat -llibswscale"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.0.1'
}
Thanks.
I have experience with Android development on Eclipse, but I'm quite new to this gradle stuff.
I created a project on Android Studio and tried adding native library support. I followed the documents on android.com
Android NDK Preview
Experimental Plugin User Guide
I bumped into the following problem and I'm not even familiar with the terminology! It says: Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'
Suggestions did not solve the problem. How can I solve it?
Here are the contents of the build.gradle and app/build.gradle:
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}
app/build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.0"
defaultConfig.with {
applicationId = "com.example.wofm"
minSdkVersion = 15
targetSdkVersion = 23
versionCode = 1
versionName = "1.0"
}
}
android.ndk {
moduleName = "wofmUtil"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles = getDefaultProguardFile('proguard-android.txt')
proguardFiles += 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
}
You should use minSdkVersion.apiLevel and targetSdkVersion.apiLevel instead of minSdkVersion and targetSdkVersion. And I also had a problem with getDefaultProguardFile() so I had to remove it.
I've been trying to upload a project to a maven repository unsuccessfully. Here is my project structure :
_root
|_ lib1 (aar)
|_ lib2 (aar)
|_ javalib (jar)
lib1 depends on lib2
lib2 depends on javalib
lib1 and lib2 have two flavors (intg and prod)
Problem is when I launch uploadArchives task I have no pom.xml created.
It seems to be due to my flavors (when I remove flavors it works fine), and I can't figure out how to fix this problem.
I really need to work with flavors ... any help is welcome ;)
here are my build.gradle files :
root :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext.versionName = "$System.properties.version"
configure(subprojects) {
apply plugin: 'maven'
group = 'com.test.build'
version = project.versionName
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/content/repositories/test/") {
authentication(userName: "admin", password: "admin123")
}
}
}
}
}
allprojects {
repositories {
jcenter()
}
}
lib1 :
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName project.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
prod{}
intg{}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
intgCompile project(path: ':lib2', configuration: 'intgRelease')
prodCompile project(path: ':lib2', configuration: 'prodRelease')
}
lib2 :
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName project.versionName
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
prod{}
intg{}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':javalib')
}
javalib :
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I finally found the answer to my issue :
it is NOT possible, but it might be possible to do it one day :
see documentation about that :
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication
I went through this problem with this solution :
// default publication is production which will be published without env name
publishNonDefault true
defaultPublishConfig "productionRelease"
if (android.productFlavors.size() > 0) {
android.libraryVariants.all { variant ->
// Publish a main artifact, otherwise the maven pom is not generated
if (android.publishNonDefault && variant.name == android.defaultPublishConfig) {
def bundleTask = tasks["bundle${name.capitalize()}"]
artifacts {
archives(bundleTask.archivePath) {
classifier null
builtBy bundleTask
}
}
}
}
}
I am not satisfied with it but it will do the job for now ...
I spend a lot time to discover why my Android project din't upload my modules to maven. The problem is because I didn't set the defaultPublishConfig inside the android {} brackets in the file build.gradle. The snippet below is how I solved my problem. You need set what flavor you wanna publish to Maven (access build variants tab in the Android Studio to see all your flavors name):
android {
...
defaultConfig {
...
defaultPublishConfig "myFlavorDebug"
}
}