Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gradle namespace & update example gradle versions. #963

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 7 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
ext.kotlin_version = '1.6.20'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
Expand All @@ -17,7 +17,7 @@ buildscript {
rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()

// DO NOT MODIFY
// BUILD_ADD_UNITY_LIBS
Expand All @@ -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'
}
Expand Down
8 changes: 5 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand All @@ -19,7 +20,7 @@ allprojects {
}

google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading