flutter-unity-view-widget
flutter-unity-view-widget copied to clipboard
Could not find :unity-classes:. Build faild with android studio
Describe the bug unity version is 2020.3.15f2. I have exported Android. Please follow the tutorial in the readme file from step 1 to step 6.5. Then open Android studio and run the application using real machine. But the operation failed:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find :unity-classes:.
Required by:
project :app > project :flutter_unity_widget
project :app > project :unityLibrary
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
To Reproduce Steps to reproduce the behavior:
-
Create a flutter project
-
Create a folder named unity and move the Unity project into
xxx/unity/xxx
-
Using Unity, Follow readme step 3 to configure
-
Go to Assets > Import Package > Custom Package and select the FlutterUnityPackage.unitypackage file. Click on Import.
-
After importing, click on Flutter and select the Export Android option (will export to android/unityLibrary) .
-
Follow readme step 6.1 to configure
include ":unityLibrary"
project(":unityLibrary").projectDir = file("./unityLibrary")
- Follow readme step 6.2 to configure
implementation project(':unityLibrary')
- Follow readme step 6.3 to configure
- Follow readme step 6.4 to configure
Expected behavior build success
Screenshots
Unity (please complete the following information):
- OS: Apple M1
- Version 11.2.3 (20D91)
Smartphone (please complete the following information):
- Device: Xiaomi M2006j10c
- OS: Anroid 10
- Version 10
Additional context I had try add unity-classes.jar as a library, but not work for me. Please help me !
I have the same problem, Add the following in build.gradle: solve the problem
allprojects {
repositories {
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
google()
jcenter()
}
}```
So I have a problem.. adding the flatDir repo @rzrobert suggests will result in my case with:
* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class bitter.jnibridge.JNIBridge found in modules jetified-unity-classes (:unity-classes:) and jetified-unity-classes (unity-classes.jar)
but not adding it will result in
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find :unity-classes:.
Required by:
project :app > project :flutter_unity_widget
I followed the approach from this tutorial https://github.com/Kion-Smith/UnityTutorial and what was suggested in #111 but no combination seems to work.
I am totally stuck and have no idea why.
EDIT: the build.gradle from the generated lib by the unityFlutter plugin from inside unity has this gralde:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
apply plugin: 'com.android.library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
so it means we need to add the unityLibrary with both src and lib jar.
If it try to trick it by changeing the gradle,build inside unittyLibrary to just use the generated jar by changing to use this configuration from issue #111:
configurations.maybeCreate("default")
artifacts.add("default", file('unity-classes.jar'))
then i get the following error:
e: /opt/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_unity_widget-4.2.1/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/OverrideUnityActivity.kt: (7, 27): Unresolved reference: UnityPlayerActivity
The output of my FlutterUnityInteration build step has the following file structure
Your project is not properly setup. You either have a missing Unity-class module or duplicate module. Solve this by manually adding Unity class jar as a module or using the flatDir
hi @juicycleff , I spent a lot of time trying to integrate that.. the output of the FlutterUnityIntgegration plugin looks like this: https://gist.github.com/adam-fu/569d3ca500021589e6d7f14ee41afc4f (the pastebin above expired I update it)...
then I tried integrate like you suggest in the tutorial.. copy this folder inside android folder. then I change android/settings.gradle to add that:
include ":unityLibrary"
project(":unityLibrary").projectDir = file("./unityLibrary")
and inside android/build.gradle i addapt my allProjects to look like that:
allprojects {
repositories {
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
google()
jcenter()
}
}
but then I run into the duplicate code error. If not include flatDir it does not know about :unity-classes
I am making a YouTube video, to show how it's done. That's the best way to atleast solve most of the issues I'm seeing
So I have a closer look on the error message, for exmple Camera2Wrapper:
Duplicate class com.unity3d.player.Camera2Wrapper found in modules jetified-unity-classes (:unity-classes:) and jetified-unity-classes (unity-classes.jar)
The file inside the unity-classes.jar is correct: https://gist.github.com/adam-fu/8de2493069b03bae0578bef97f975d93 it can be found in com/unity3d/player/Camera2Wrapper.class and there is only on file.
I suspected maybe some problem related to the plugin code and gradle version so i upgarded com.android.tools.build:gradle:4.1.0 and gradle 6.7 to com.android.tools.build:gradle:4.2.2 and gradle 7.2 and upgraded kotlin version to 1.4.31 still having the same duplicate class errors..
The details on my machine relevant for the gradle build:
./gradlew -v
------------------------------------------------------------
Gradle 7.2
------------------------------------------------------------
Build time: 2021-08-17 09:59:03 UTC
Revision: a773786b58bb28710e3dc96c4d1a7063628952ad
Kotlin: 1.5.21
Groovy: 3.0.8
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 14.0.2 (Private Build 14.0.2+12-Ubuntu-120.04)
OS: Linux 5.8.0-050800-generic amd64
Hi @juicycleff ,
I finally understand my error. My unity project was outside of my flutter project.
I think it needs to be stressed out more in the docs that if the project is not in
On Emulator I have now issue #467 on real device it finally works :)
I have the same problem, Add the following in build.gradle: solve the problem
allprojects { repositories { flatDir { dirs "${project(':unityLibrary').projectDir}/libs" } google() jcenter() } }
Thank you! This fixed my problem.
By the way, this took me a while because I placed the code in the wrong build.gradle
file. You should replace the existing allprojects
from android/build.gradle
with this one from @Baleen-Y
I have a similar error, I still don't understand what exactly needs to be done when you say that the Unity project is located elsewhere?
EDIT: I put the Unity project in the Flutter folder of the project. And also redirected the search for project files as follows. I get exactly the same situation.
Please ping me if you have solution of this
Execution failed for task ':app:checkDebugDuplicateClasses'. [ ] > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable [ ] > Duplicate class bitter.jnibridge.JNIBridge found in modules jetified-unity-classes (:unity-classes:) and jetified-unity-classes (unity-classes.jar) [ ] Duplicate class bitter.jnibridge.JNIBridge$a found in modules jetified-unity-classes (:unity-classes:) and jetified-unity-classes (unity-classes.jar)
file structure @SnowyTusk Did you find any solution for this?