3

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.

dragostis
  • 2,574
  • 2
  • 20
  • 39

1 Answers1

1

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

Community
  • 1
  • 1
mkc
  • 395
  • 4
  • 14