androidfluttergradleaapt

Cannot run Flutter plugin: AAPT: error: unexpected element <uses-native-library>


I actually create my first android native plugin for flutter. This plugin will be use to implement a hardware android dependency (camera kit who use arcore and camera stream for virtual reallity).

This dependency seems to be in beta, but I successfully created a native android app with it. So I convert my activity to a flutter plugin. I successfully create my own plateform view with a viewStub who will use by camerakit to inflate his layout. But when I attempt to run my flutter exemple, I get the following error:

* 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>.

Effectively, when I open one of the camerakit librairy I can see thus lines in the manifest:

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

Here is my android's build.gradle plugin content:

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

Do you have any suggestion to resolve this ? Is it possible to embded this type of library in flutter app ? Thank a lot !


Solution

  • Likely because the Gradle build tools version you're using doesn't support <uses-native-library> tag so try upgrading it.


    For example:

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