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 ecd64b31b..c33f636e0 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,9 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 31 + compileSdkVersion 34 + + namespace 'com.xraph.plugin.flutter_unity_widget_example' sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -39,8 +41,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 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");