无法运行 Flutter 插件:AAPT:错误:意外元素 <uses-native-library>

jer*_*pas 4 android gradle aapt flutter

我实际上为 flutter 创建了我的第一个 android 原生插件。该插件将用于实现硬件 android 依赖项(使用 arcore 和相机流进行虚拟现实的相机套件)。

这种依赖关系似乎处于测试阶段,但我成功地用它创建了一个本机 Android 应用程序。所以我将我的 Activity 转换为 Flutter 插件。我使用 viewStub 成功创建了自己的平台视图,camerakit 将使用 viewStub 来扩展其布局。但是当我尝试运行我的 flutter 示例时,出现以下错误:

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     C:\Users\dupas\Desktop\camerakit\example\build\app\intermediates\packaged_manifests\debug\AndroidManifest.xml:83: AAPT: error: unexpected element <uses-native-library> found in <manifest><application>.

     C:\Users\dupas\Desktop\camerakit\example\build\app\intermediates\packaged_manifests\debug\AndroidManifest.xml:86: AAPT: error: unexpected element <uses-native-library> found in <manifest><application>.

     C:\Users\dupas\Desktop\camerakit\example\build\app\intermediates\packaged_manifests\debug\AndroidManifest.xml:89: AAPT: error: unexpected element <uses-native-library> found in <manifest><application>.

     C:\Users\dupas\Desktop\camerakit\example\build\app\intermediates\packaged_manifests\debug\AndroidManifest.xml:92: AAPT: error: unexpected element <uses-native-library> found in <manifest><application>.
Run Code Online (Sandbox Code Playgroud)

实际上,当我打开相机套件库之一时,我可以在清单中看到这样的行:

<uses-native-library
    android:name="libOpenCL-pixel.so"
    android:required="false" />
<uses-native-library
    android:name="libOpenCL.so"
    android:required="false" />
<uses-native-library
    android:name="libGLES_mali.so"
    android:required="false" />
<uses-native-library
    android:name="libPVROCL.so"
    android:required="false" />
Run Code Online (Sandbox Code Playgroud)

这是我的android的build.gradle插件内容:

group 'com.example.camerakit'
version '1.0-SNAPSHOT'

ext {
    bundledMavenRepo = rootProject.file('C:\\Users\\dupas\\Desktop\\camerakit\\android\\maven')
}

buildscript {
    ext.kotlin_version = '1.6.10'
    ext.cameraKitVersion = "1.11.0"
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

rootProject.allprojects {
    repositories {
        maven{
            url bundledMavenRepo.toURI()
        }
        google()
        mavenCentral()
    }
}

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

android {
    compileSdkVersion 31

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    buildFeatures {
        viewBinding true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 21
    }
}

android {
    defaultConfig {
        vectorDrawables.useSupportLibrary = true
    }
}
allprojects {
    ext {
        cameraKitVersion = "1.11.0"
        cameraKitApplicationId = "0.0.0"
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    // The main CameraKit artifact that provides all the core functionality.
    // It is not necessary to define it here if support-camera-layout artifact is
    // used as it transitively depends on it, however it is kept for the reference.
    implementation "com.snap.camerakit:camerakit:$cameraKitVersion"
    // Provides convenience Kotlin specific extensions to the public CameraKit API.
    implementation "com.snap.camerakit:camerakit-kotlin:$cameraKitVersion"
    // Provides an opinionated but extensible implementation that wraps
    // camera as well as CameraKit Session management with a View that can be
    // embedded into any Activity or Fragment where CameraKit integration is needed.
    implementation "com.snap.camerakit:support-camera-layout:$cameraKitVersion"
    // Optional dependency that provides location access to certain lenses.
    // Used by the support-camera-layout when creating the Source<LocationProcessor>
    // for the CameraKit Session, if removed, falls back to default, no-op implementation.
    implementation "com.snap.camerakit:support-gms-location:$cameraKitVersion"
    // Optional dependency that provides ArCore backed Source<ImageProcessor> to enable
    // depth and other ArCore specific features in lenses that require them.
    // Used by the support-camera-layout but can be safely removed if not needed.
    implementation "com.snap.camerakit:support-arcore:$cameraKitVersion"
    // Optional dependency that provides customizable lenses carousel view.
    implementation "com.snap.camerakit:support-lenses-carousel:$cameraKitVersion"
    implementation "com.snap.camerakit:lenses-bundle:$cameraKitVersion"

    implementation "androidx.core:core-ktx:1.7.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Run Code Online (Sandbox Code Playgroud)

您有什么建议来解决这个问题吗?是否可以将这种类型的库嵌入到flutter应用程序中?非常感谢 !

小智 18

可能是因为您使用的Gradle 构建工具版本不支持<uses-native-library>标签,因此请尝试升级它。


例如:

安卓/build.gradle:

=>classpath 'com.android.tools.build:gradle:7.1.2'

android/gradle/wrapper/gradle-wrapper.properties:

=>distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip