From e797ccde98e5c2f2520bcd2df85320802c522ba8 Mon Sep 17 00:00:00 2001 From: timbotimbo Date: Tue, 25 Jun 2024 20:59:21 +0200 Subject: [PATCH 1/3] Update example gradle & sdk versions. --- example/android/app/build.gradle | 6 +++--- example/android/build.gradle | 9 +++++---- example/android/gradle/wrapper/gradle-wrapper.properties | 2 +- example/pubspec.yaml | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index ecd64b31b..2220130e3 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 31 + compileSdkVersion 34 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -39,8 +39,8 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.xraph.plugin.flutter_unity_widget_example" - minSdkVersion 28 - targetSdkVersion 31 + minSdkVersion 28 // >= unity minSdk in player settings + targetSdkVersion 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/example/android/build.gradle b/example/android/build.gradle index bd59fa42d..116fd51ba 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,13 @@ buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.8.22' repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + // Unity recommended gradle version https://docs.unity3d.com/Manual/android-gradle-overview.html (higher versions do often work) + classpath 'com.android.tools.build:gradle:7.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -19,7 +20,7 @@ allprojects { } google() - jcenter() + mavenCentral() } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 90f271dfd..595fb867a 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-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip diff --git a/example/pubspec.yaml b/example/pubspec.yaml index fb9991c84..7e1f7bdef 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -6,7 +6,7 @@ description: Demonstrates how to use the flutter_unity_widget plugin. publish_to: "none" # Remove this line if you wish to publish to pub.dev environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" dependencies: cupertino_icons: ^1.0.0 From 9131721e715abaf85bf6f15516ee32269221f550 Mon Sep 17 00:00:00 2001 From: timbotimbo Date: Tue, 25 Jun 2024 21:15:41 +0200 Subject: [PATCH 2/3] Add namespace for Android gradle plugin (AGP) 8 compatibility. --- CHANGELOG.md | 1 + android/build.gradle | 9 +++++++-- example/android/app/build.gradle | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed52cdb21..a098758fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Pending (master branch only) * [Android] Fix touch detection when using Unity's New Input System. [#938](https://github.com/juicycleff/flutter-unity-view-widget/pull/938) * [Android] Workaround for mUnityplayer error in Unity plugins using the AndroidJavaProxy. [#908](https://github.com/juicycleff/flutter-unity-view-widget/pull/908) +* [Android] Add namespace for Android gradle plugin (AGP) 8 compatibility. ## 2022.2.1 diff --git a/android/build.gradle b/android/build.gradle index 8a61bc310..37b5eb73e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,7 +5,7 @@ buildscript { ext.kotlin_version = '1.6.20' repositories { google() - jcenter() + mavenCentral() } dependencies { @@ -17,7 +17,7 @@ buildscript { rootProject.allprojects { repositories { google() - jcenter() + mavenCentral() // DO NOT MODIFY // BUILD_ADD_UNITY_LIBS @@ -35,6 +35,11 @@ apply plugin: 'kotlin-android' android { compileSdkVersion 29 + // backwards compatible for old gradle versions without namespace + if (project.android.hasProperty("namespace")) { + namespace 'com.xraph.plugin.flutter_unity_widget' + } + sourceSets { main.java.srcDirs += 'src/main/kotlin' } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 2220130e3..c33f636e0 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -27,6 +27,8 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 34 + + namespace 'com.xraph.plugin.flutter_unity_widget_example' sourceSets { main.java.srcDirs += 'src/main/kotlin' From f3c145fcd81ea937030afefa4343df149f604b18 Mon Sep 17 00:00:00 2001 From: timbotimbo Date: Mon, 8 May 2023 13:25:15 +0200 Subject: [PATCH 3/3] Add namespace to unityLibrary export. --- .../Assets/FlutterUnityIntegration/Editor/Build.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs b/example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs index 7b2ceba27..69cf1d1ca 100644 --- a/example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs +++ b/example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs @@ -332,6 +332,14 @@ private static void ModifyAndroidGradle(bool isPlugin) buildText = buildText.Replace(" + unityStreamingAssets.tokenize(', ')", ""); buildText = Regex.Replace(buildText, "ndkPath \".*\"", ""); + // check for namespace definition (Android gradle plugin 8+), add a backwards compatible version if it is missing. + if(!buildText.Contains("namespace")) + { + buildText = buildText.Replace("compileOptions {", + "if (project.android.hasProperty(\"namespace\")) {\n namespace 'com.unity3d.player'\n }\n\n compileOptions {" + ); + } + if(isPlugin) { buildText = Regex.Replace(buildText, @"implementation\(name: 'androidx.* ext:'aar'\)", "\n");