ブログアーカイブ
GradleException, androidx.annotation.NonNull
Android StudioでFlutterアプリを作成すると、android/app/build.gradle ファイルの GradleException の箇所、android/app/src/kotlin/ 以下の MainActivity.kt ファイルの androidx.annotation.NonNull の箇所、android/app/src/main/java/io.flutter/plugins/GeneratedPluginRegistrant.java ファイルの import androidx.annotation.Keep の Keep の箇所がそれぞれ赤字で表示されエラーが発生する。
Gradle project sync failed. が発生する。Frameworks Detected. が表示されない。Gradleでサポートされていないプロジェクト 等が表示される。
- File – Settings – Kotlin Compiler の Kotlin to JVM – Target JVM Version を 1.6 から 1.8 に変更します。プロジェクトを開きなおします。
- File – Project Structure… の Project Setting – Project の Project SDK を <NO SDK> の場合に Android API 28 Platform などに変更します。
- android/gradle.properties ファイルを android/app ディレクトリーにコピーします。またはgradle.propertiesを作成します。
- プロジェクト内の android/gradle ディレクトリーを android/app/ と / (ProjectRoot) にコピーします。gradle-wrapper.jar ファイルとgradle-wrapper.properties ファイルが含まれます。
- プロジェクト内の /.idea, /.dart_tool, /android/.idea, /android/.gradle ディレクトリーを削除します。キャッシュフォルダーと思われますので削除しても問題は発生しません。
- %userprofile% の .Android Studio 3.5/system/cache, .gradle ディレクトリーを削除します。
GradleException のエラーは依然として発生する場合があります。app/build.gradleファイルの def flutterRoot の個所を次のように書き換えると発生しなくなります。
def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") // throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") }
gradle.properties
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
以前の投稿です。
Tools – Flutter – Open for Editing in Android Studio を選択します。This Window で問題ないようです。
File – Settings – Kotlin Compiler の Kotlin to JVM – Target JVM Version を 1.6 から 1.8 に変更します。プロジェクトを開きなおします。
File – Project Structure… の Project Setting – Project の Project SDK を <NO SDK> の場合に Android API 28 Platform などに変更します。
File – Invalidate Chches / Restart を選択して Invalidate を実行します。
こちらのサイトの情報 (https://stackoverflow.com/questions/56607089/new-gradle-sync-is-not-supported-due-to-containing-kotlin-modules-using-an-unsup)が参考になりました。なかなか見つからなかった。
Flutter, build.gradle Release
key.properties
keyAlias='key'
keyPassword='<password from previous step>'
storeFile='<location of the key store file, such as /Users//key.jks>'
storePassword='<password from previous step>'
android/app/build.gradle
.....
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
.....
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
.....
Build – Flutter – Build APK を実行すると、flutter storefile path may not be null or empty string. path=’null’ エラーが発生してAPKファイルが生成されません。
(yourProject)/android/app ディレクトリーと (yourProject)/android ディレクトリーに key.properties ファイルと key.jks ファイルを配置します。build.gradle ファイルと同じディレクトリーにそれぞれ配置します。
セキュリティリーの問題がありますが直接指定する方法もあります。
keyAlias 'key'
keyPassword '<password from previous step>'
storeFile file('key.jks')
storePassword '<password from previous step>'
‘<password from previous step>‘, ‘<password from previous step>‘ 等は実際に使用するパスワードに置き換えます。