Cannot run Flutter plugin: AAPT: error: unexpected element <uses-native-library>
Cannot run Flutter plugin: AAPT: error: unexpected element <uses-native-library>
我实际上创建了我的第一个 android flutter 原生插件。此插件将用于实现硬件 android 依赖项(使用 arcore 和相机流进行虚拟现实的相机套件)。
此依赖项似乎处于测试阶段,但我成功地使用它创建了一个本机 android 应用程序。
所以我将 activity 转换为 flutter 插件。我使用 viewStub 成功创建了自己的平台视图,camerakit 将使用它来扩充他的布局。
但是当我尝试 运行 我的 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>.
实际上,当我打开其中一个 camerakit 库时,我可以在清单中看到这样的行:
<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" />
这是我的 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"
}
你有什么解决这个问题的建议吗?是否可以将这种类型的库嵌入到 flutter 应用程序中?
非常感谢!
可能是因为您使用的 Gradle 构建工具 版本不支持 <uses-native-library>
标签,因此尝试升级它。
例如:
android/build.gradle:
=> classpath 'com.android.tools.build:gradle:7.1.2'
android/gradle/wrapper/gradle-wrapper.属性:
=> distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
我实际上创建了我的第一个 android flutter 原生插件。此插件将用于实现硬件 android 依赖项(使用 arcore 和相机流进行虚拟现实的相机套件)。
此依赖项似乎处于测试阶段,但我成功地使用它创建了一个本机 android 应用程序。 所以我将 activity 转换为 flutter 插件。我使用 viewStub 成功创建了自己的平台视图,camerakit 将使用它来扩充他的布局。 但是当我尝试 运行 我的 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>.
实际上,当我打开其中一个 camerakit 库时,我可以在清单中看到这样的行:
<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" />
这是我的 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"
}
你有什么解决这个问题的建议吗?是否可以将这种类型的库嵌入到 flutter 应用程序中? 非常感谢!
可能是因为您使用的 Gradle 构建工具 版本不支持 <uses-native-library>
标签,因此尝试升级它。
例如:
android/build.gradle:
=> classpath 'com.android.tools.build:gradle:7.1.2'
android/gradle/wrapper/gradle-wrapper.属性:
=> distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip