5

我制作了一个自定义模块,并通过“api”配置在其中包含了 tensorflow-lite 依赖项。我建立它的 aar。现在我创建一个新项目并将 aar 放在 libs 文件夹中。但我只能访问我创建的类,而不能访问 tensorflow api。如何在不再次包含它们的情况下也使用传递依赖项?

当我在博客( https://medium.com/mindorks/implementation-vs-api-in-gradle-3-0-494c817a6fa)中读到时,我已经用“api”替换了“实现” 。

build.gradle(模块:mylib)

apply plugin: 'com.android.library'
android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    aaptOptions{
        noCompress "tflite"
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    api 'androidx.appcompat:appcompat:1.1.0-alpha04'
    api 'org.tensorflow:tensorflow-lite:0.0.0-gpu-experimental'
}

build.gradle(模块:新项目中的两个):

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
                cppFlags "-std=c++11", "-frtti", "-fexceptions"
            }
        }
        ndk {
            abiFilters 'armeabi-v7a'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    aaptOptions {
        noCompress "tflite"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}

repositories {
    maven { url 'https://google.bintray.com/tensorflow' }
    flatDir {
        dirs 'libs'
    }
    mavenCentral()
}

dependencies {
    api fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    api project(':openCVLibrary341')
    api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
4

0 回答 0