问题描述
我试图构建Flutter应用程序并在设备上运行它,但出现此错误:
我在旧设备Samsung galaxy S5(SM G900I)上运行我的APP,但过去我成功在该设备上运行我的APP。 我认为我的版本在gradle或清单中有错误。 为了解决该错误并在设备上安装并运行我的应用程序,我需要做些什么?
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: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$FlutterRoot/packages/Flutter_tools/gradle/Flutter.gradle"
android {
compileSdkVersion 28
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.example.bar_iland_app"
minSdkVersion 21
targetSdkVersion 28
versionCode FlutterVersionCode.toInteger()
versionName FlutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bar_iland_app">
<!-- 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. -->
<!--uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/-->
<application
android:name="io.Flutter.app.FlutterApplication"
android:label="bar_iland_app"
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">
<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>
解决方法
将您的SDK更新到android文件夹中的最新版本 android { compileSdkVersion 30
defaultConfig {
targetSdkVersion 30
}
}有时,当您自动更改时,无法下载 如果不起作用,请重新安装android sdk。它可以正常工作或更新sdk