flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

Could not find :unity-classes:. Build faild with android studio

Open rzrobert opened this issue 2 years ago • 12 comments

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:

  1. Create a flutter project

  2. Create a folder named unity and move the Unity project into xxx/unity/xxx

  3. Using Unity, Follow readme step 3 to configure

  4. Go to Assets > Import Package > Custom Package and select the FlutterUnityPackage.unitypackage file. Click on Import.

  5. After importing, click on Flutter and select the Export Android option (will export to android/unityLibrary) .

  6. Follow readme step 6.1 to configure

include ":unityLibrary"
project(":unityLibrary").projectDir = file("./unityLibrary")
  1. Follow readme step 6.2 to configure
implementation project(':unityLibrary')
  1. Follow readme step 6.3 to configure
  2. Follow readme step 6.4 to configure

Expected behavior build success

Screenshots

unity_error

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 !

rzrobert avatar Aug 14 '21 02:08 rzrobert

I have the same problem, Add the following in build.gradle: solve the problem

allprojects {
    repositories {
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
        google()
        jcenter()
    }
}```

Baleen-Y avatar Aug 31 '21 04:08 Baleen-Y

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

adam-fu avatar Sep 25 '21 12:09 adam-fu

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

juicycleff avatar Sep 26 '21 09:09 juicycleff

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

adam-fu avatar Sep 26 '21 17:09 adam-fu

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

juicycleff avatar Sep 26 '21 17:09 juicycleff

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

adam-fu avatar Sep 26 '21 19:09 adam-fu

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 /unity/ it will fail.. https://github.com/juicycleff/flutter-unity-view-widget#steps maybe add a word of warning, that your plugin only works in this setup.

On Emulator I have now issue #467 on real device it finally works :)

adam-fu avatar Sep 27 '21 08:09 adam-fu

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

AngCosmin avatar Oct 27 '21 15:10 AngCosmin

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. image

SnowyTusk avatar Jul 27 '22 01:07 SnowyTusk

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)

arshad-dqot avatar Sep 09 '22 13:09 arshad-dqot

file structure @SnowyTusk Did you find any solution for this?

Mirza65 avatar Jan 06 '23 14:01 Mirza65