我正在为android构建一个flutter应用程序。
我从…更新了gradle构建工具版本
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.1.3'
现在我得到构建错误…
Execution failed for task ':app:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/home/user/src/myapp/build/app/intermediates/packaged_manifests/release/AndroidManifest.xml:34: AAPT: error: attribute android:usesPermissionFlags not found.
我的构建。Gradle如下:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services' // Google Services plugin
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.me.myapp"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
我gradle-wrapper。
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.8.1-all.zip
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="tenera_provision"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
调整您的android/app/build.gradle
,使您的应用程序编译针对最新的Android SDK:
android {
compileSdkVersion 31
}
现在还不需要调整targetSdkVersion。
usesPermissionFlags
是最近添加的,你的一些插件可能已经支持它了。
https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location有所有的细节。
检查构建。Gradle in android/app
compileSdkVersion 30minSdkVersion 16targetSdkVersion 30
如果这没有修复,那么可能你在android manifest中缺少权限在android/app/src/main/AndroidManifest.xml
错误消息一般来自AAPT2。
可以看到,这个属性从API级别17开始就存在了。
对于调试目的,合并的AndroidManifest.xml
@line 34宁愿是有趣的,因为android:usesPermissionFlags
甚至来自哪里的问题仍然存在,因为:app
模块内的AndroidManifest.xml
没有这一行,合并的版本需要从某处获得它-这只能是另一个模块或一些AAR
库。
buildToolsVersion "30.0.3"
应该可以工作,但由于没有声明任何其他内容,这仍然应该是类似的…然而,Android Studio(存档)的版本也起着作用(它需要与Gradle插件的版本匹配,即4.1.3
,与Gradle4.4
)…或者对于当前的"北极狐",这将是7.0.3
,使用Gradle7.2
(您正在构建一个遗留项目)。
aapt2 version
应该返回:
Android资产打包工具(aapt) 2.19-6966805
这将是要使用的版本表。
实际上Gradle也有可能太新了。
顺便说一下…我甚至可以证明这是一个假设(除了:clean
任务通常驻留在根build.gradle
中,而不是模块build.gradle
,这是一个潜在的问题):
task clean(type: Delete) {
delete rootProject.buildDir
}
表示./build
被删除,但./app/build
不被删除。我甚至更进一步,不仅删除了./build
,还删除了~/.gradle/cache
。如果有更多的Java/Kotlin模块存在,请确保其中没有一个是使用过时的buildToolsVersion
构建的。
当它保持在模块build.gradle
内时,它应该将它们全部删除:
task clean(type: Delete) {
delete rootProject.buildDir
delete project.buildDir
}
如果你正在升级gradle构建工具到更高的级别,那么你还需要从android/gradle/wrapper/gradle-wrapper.properties中将包装器升级到某个稳定版本。例如,如果您将工具更新为classpath 'com.android.tools.build:gradle:4.2.1'
,并将包装器版本更新为6.8.1。然后应用程序应该构建。
你的编译和目标sdk绝对没问题。如果标志问题仍然存在,将此添加到您的清单
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />