From d1c883a001dbdb9f71a0ab42607bb5875de33f1e Mon Sep 17 00:00:00 2001 From: Nils Strelow Date: Mon, 9 Nov 2020 20:28:28 +0100 Subject: [PATCH] chore: Update example's android project --- example/android/.gitignore | 17 ++++---- example/android/app/build.gradle | 30 ++++++++------ .../android/app/src/main/AndroidManifest.xml | 41 +++++++++++-------- .../example/chewieexample/MainActivity.java | 14 ------- .../MainActivity.kt | 2 +- .../main/res/drawable/launch_background.xml | 2 +- .../app/src/main/res/values/styles.xml | 12 +++++- example/android/build.gradle | 4 +- example/android/gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/settings.gradle | 18 ++++---- 11 files changed, 75 insertions(+), 69 deletions(-) delete mode 100644 example/android/app/src/main/java/com/example/chewieexample/MainActivity.java rename example/android/app/src/main/kotlin/com/example/{example => chewieexample}/MainActivity.kt (73%) diff --git a/example/android/.gitignore b/example/android/.gitignore index 65b7315af..0a741cb43 100644 --- a/example/android/.gitignore +++ b/example/android/.gitignore @@ -1,10 +1,11 @@ -*.iml -*.class -.gradle +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat /local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index f31fcfca9..72fecefc7 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -11,15 +11,25 @@ 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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 + compileSdkVersion 29 - compileOptions { - sourceCompatibility 1.8 - targetCompatibility 1.8 + sourceSets { + main.java.srcDirs += 'src/main/kotlin' } lintOptions { @@ -27,13 +37,11 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.chewieexample" minSdkVersion 21 - targetSdkVersion 28 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + targetSdkVersion 29 + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName } buildTypes { @@ -50,7 +58,5 @@ flutter { } dependencies { - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.1' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index d08beb7cb..284147c23 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,39 +1,44 @@ - - - - + + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" + /> + + + + diff --git a/example/android/app/src/main/java/com/example/chewieexample/MainActivity.java b/example/android/app/src/main/java/com/example/chewieexample/MainActivity.java deleted file mode 100644 index 95de0f938..000000000 --- a/example/android/app/src/main/java/com/example/chewieexample/MainActivity.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.example.chewieexample; - -import android.os.Bundle; - -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; - -public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } -} diff --git a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/chewieexample/MainActivity.kt similarity index 73% rename from example/android/app/src/main/kotlin/com/example/example/MainActivity.kt rename to example/android/app/src/main/kotlin/com/example/chewieexample/MainActivity.kt index e793a000d..237ee7d9f 100644 --- a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt +++ b/example/android/app/src/main/kotlin/com/example/chewieexample/MainActivity.kt @@ -1,4 +1,4 @@ -package com.example.example +package com.example.chewieexample import io.flutter.embedding.android.FlutterActivity diff --git a/example/android/app/src/main/res/drawable/launch_background.xml b/example/android/app/src/main/res/drawable/launch_background.xml index 304732f88..f74085f3f 100644 --- a/example/android/app/src/main/res/drawable/launch_background.xml +++ b/example/android/app/src/main/res/drawable/launch_background.xml @@ -1,7 +1,7 @@ - + + + + diff --git a/example/android/build.gradle b/example/android/build.gradle index d4225c790..3100ad2d5 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,11 +1,13 @@ buildscript { + ext.kotlin_version = '1.3.50' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.2' + classpath 'com.android.tools.build:gradle:3.5.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index d2032bce8..a6738207f 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx1536M -android.enableJetifier=true android.useAndroidX=true +android.enableJetifier=true android.enableR8=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 9372d0f3f..296b146b7 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 5a2f14fb1..44e62bcf0 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,15 +1,11 @@ include ':app' -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } -} +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory -} +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"