Android 实验级插件看不到我的库模块

标签 android android-ndk android-gradle-plugin build.gradle

我正在将 Android 库 (.aar) 编译为包含一些 native 代码并需要一些库的模块。这是 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'])
}

这会编译所有内容(我检查了 .class 和 .so 文件),但是 .aar 文件几乎是空的,没有类或动态库。 (约 2.3KB)

在第二个模块中,我将其添加为依赖项:

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'
}

但是当我尝试从其他模块添加 Java 类时,我得到:Error:(12, 29) error: package org.anima.mrubybridge does not exist,很可能是因为它们不在 .aar 中。

我已经将该模块添加为依赖项(compile project(':mrubybridge')),但它并没有真正帮助。

最佳答案

我遇到了同样的问题。这个答案为我解决了:

@ Radix

“将 .aar 文件放在应用程序库目录中(如果需要,请创建它),然后,在您的应用程序 build.gradle 中添加以下代码”:

dependencies {
   compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
 }
repositories{
      flatDir{
              dirs 'libs'
       }
 }

Adding local .aar files to Gradle build using "flatDirs" is not working

关于Android 实验级插件看不到我的库模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32932555/

相关文章:

connection - Android Studio 0.8.6 Gradle项目刷新失败,连接重置

依赖于另一个模块的 Android NDK 模块

c++ - Android NDK 库 .a 文件中的 gnuSTL_shared 和 gnuSTL_static 有什么区别?

Android Gradle 插件 4.2.0 R8 ArrayIndexOutOfBoundsException

android - 退出android中的应用程序

c++ - Android中的Jni层

google-app-engine - Android Studio 无法识别 gradle 2.10

android 将圆分成N等份并知道每个分割点的坐标

android - __updatedAt 未更新 : Azure Mobile Services

java - 使用 Layoutinflater 和 View 时 Activity 布局中没有数据