【问题标题】:Plugin with id 'com.android.model.native' not found未找到 ID 为“com.android.model.native”的插件
【发布时间】:2021-01-08 01:45:14
【问题描述】:

我正在尝试使用 Android Studio 从我的 C 项目中开发一个模块。我遇到了问题

未找到 ID 为“com.android.model.native”的插件。

我做错了什么?

谢谢!

下面是App级别的build.gradle


apply plugin: "com.android.model.native"

model {
    android {

        compileSdkVersion 27

        defaultConfig {
            applicationId = 'com.example.androidthings.nativepio'
            minSdkVersion 27
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
        }

        ndk {
            //platformVersion = "21"
            moduleName "libusb"
            ldLibs.addAll(["log"])
            CFlags.add("-Wall")
            CFlags.add("-I" + file("src/main/jni/android").absolutePath)
            CFlags.add("-O3")
        }

        sources {
            main {
                jni {
                    exportedHeaders {
                        srcDir "src/main/jni/libusb"
                    }
                    dependencies {
                        project ":dependency_module"
                    }
                }
            }
        }

    }
}

这里是项目级构建gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'

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

【问题讨论】:

    标签: android gradle android-ndk


    【解决方案1】:

    此插件是当前构建系统的 experimental and old version 的一部分。

    您应该重写您的 gradle 文件以使用 the current build system。要么让 Android Studio 通过linking to your CMake file 生成必要的添加,要么从HelloJNI 示例等已知良好的示例中复制:

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    
    android {
        compileSdkVersion 29
        ndkVersion '21.2.6472646'
    
        defaultConfig {
            applicationId 'com.example.hellojni'
            minSdkVersion 23
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
        }
        buildFeatures {
            viewBinding true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'),
                        'proguard-rules.pro'
            }
        }
        externalNativeBuild {
            cmake {
                path "src/main/cpp/CMakeLists.txt"
            }
        }
    
        flavorDimensions 'cpuArch'
        productFlavors {
            arm8 {
                dimension 'cpuArch'
                ndk {
                    abiFilters 'arm64-v8a', 'armeabi-v7a'
                }
            }
            x86_64 {
                dimension 'cpuArch'
                ndk {
                    abiFilters 'x86_64', 'x86'
                }
            }
            universal {
                dimension 'cpuArch'
                // include all default ABIs. with NDK-r16,  it is:
                //   armeabi-v7a, arm64-v8a, x86, x86_64
            }
        }
    }
    
    dependencies {
        implementation 'androidx.appcompat:appcompat:1.1.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    }
    

    【讨论】:

      猜你喜欢
      • 2020-03-01
      • 1970-01-01
      • 2019-08-04
      • 2017-12-20
      • 2017-06-03
      • 2021-11-05
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多