yasirkula / UnityIonicIntegration

A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
104 stars 32 forks source link

Type bitter.jnibridge.JNIBridge$a is defined multiple times #69

Closed LasLamos closed 3 years ago

LasLamos commented 3 years ago

Description of the bug

I'm currently working on a little project to integrate a unity app into an existing ionic app. After adding the dependencies to the build.gradle file of the ionic app i get the error message:

Type bitter.jnibridge.JNIBridge$a is defined multiple times: ..\platforms\android\app\build\intermediates\external_file_lib_dex_archives\debug\out\0_unity-classes.jar:classes.dex, ..\platforms\android\app\build\intermediates\external_file_lib_dex_archives\debug\out\1_unity-classes.jar:classes.dex

Reproduction steps

What steps have i taken?

I edited the settings.gradle of the exported Ionic android project to look like this: image

I edited the build.gradle dependency block of the exported Ionic Android project and added the implementation line: image

I edited the UnityProject Gradle File and both AndroidManifests. But every time i want to build the project, i get the error message above.

Platform specs

Please provide the following info if this is a Unity 3D repository.

-Ionic Info: image

Did anyone else get this error or knows how to fix it?

yasirkula commented 3 years ago

"absolute path to unityLibraryFolder" points to the folder you've selected when building your Unity project, right?

LasLamos commented 3 years ago

Yes, but i had to use the Path to the unityLibrary Folder inside UnityProject because i was getting an error that it could'nt be found.

yasirkula commented 3 years ago

That's probably why. I've always pointed it to the Unity build folder, not a subfolder of it nor a different folder. You should give more details about the library couldn't be found error.

I'm assuming that you didn't skip this step:

Inside jniLibs folder of android module, delete unity-classes.jar, if exists

LasLamos commented 3 years ago

If i'm setting everything to UnityProject just as the instruction says im getting this error:

Build file 'E:\Dennis\Desktop\IonicPlugin\UnityProject\build.gradle' line: 20

A problem occurred evaluating project ':UnityProject'.

Project with path ':unityLibrary' could not be found in project ':UnityProject'.

Line 20 of E:\Dennis\Desktop\IonicPlugin\UnityProject\build.gradle:

flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }

I Changed the Lines in setting.gradle to:

include ':UnityProject'
project(':UnityProject').projectDir = new File('E:\\Dennis\\Desktop\\IonicPlugin\\UnityProject')

And i changed the build.gradle dependencies to:

    implementation project(':UnityProject')

In my jniLibs Folder was no unity-classes.jar and there still isnt,

yasirkula commented 3 years ago

What is :unityLibrary? I can't find it in the documentation.

LasLamos commented 3 years ago

UnityLibrary is a subfolder in the exported UnityProject. After eyxporting my UnityProject to an empty folder the structure looks like this: image

yasirkula commented 3 years ago

I think you should change flatDirs as follows:

flatDir {
   dirs 'E:\\Dennis\\Desktop\\IonicPlugin\\UnityProject\\libs'
}

or maybe

flatDir {
   dirs 'E:\\Dennis\\Desktop\\IonicPlugin\\UnityProject\\unityLibrary'
}
LasLamos commented 3 years ago

If i'm editing the flatDirs i get yet another error, so im guessing something is messed up in my build.gradle files. Maybe i should start a new Unity and Ionic Project and start with new Builds.

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.

Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'. Could not resolve project :UnityProject. Required by: project :app No matching configuration of project :UnityProject was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but:

  • None of the consumable configurations have attributes.
LasLamos commented 3 years ago

Okay, so i created a new UnityProject, added the IonicComms file and exported the project as an android project. I created an new blank ionic project, added the plugin and added the codesnippet and build the android project.

After that i edited the settings.gradle and build.gradle of the ionic android export, but after clicking on 'Sync Now' im getting the same result:

image

And after editing the flatdirs as you suggested im getting the same error as before:

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :UnityProject.
     Required by:
         project :app
      > No matching configuration of project :UnityProject was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but:
          - None of the consumable configurations have attributes.
yasirkula commented 3 years ago

I don't get it. Where does this :unityLibrary come from? I've shown you how you should replace that line in flatDir. Did you not apply that change?

LasLamos commented 3 years ago

As soon as i export my project from Unity, the folder has a unityLibrary folder in it: image

Within the exported UnityProject is a build.gradle, which contains the line:

            dirs "${project(':unityLibrary').projectDir}/libs"

which results in the mentioned error

I replaced the line as you suggested with

flatDir {
   dirs 'E:\\Dennis\\Desktop\\IonicPlugin\\UnityProject\\unityLibrary'
}

and i tried the other suggestion as well:

flatDir {
   dirs 'E:\\Dennis\\Desktop\\IonicPlugin\\UnityProject\\libs'
}

But after applying the change to the flat dir, i get the error message i posted before:

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :UnityProject.
     Required by:
         project :app
      > No matching configuration of project :UnityProject was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but:
          - None of the consumable configurations have attributes.

I'm sorry for any misunderstandings as english isnt my first language. And thank you very much for your help so far!

yasirkula commented 3 years ago

Ah, so :unityLibrary comes with Unity, alright. I thought you were adding it to build.gradle. I think Unity as a Library documentation will prove useful here. Please follow step 3 there. You'll probably have to change some/all occurrences of :unityLibrary there to :UnityProject:unityLibrary.

LasLamos commented 3 years ago

I followed the steps and changed all unityLibrary Occurences to your suggestion, but now i get the same error as in the beginning:

Type bitter.jnibridge.JNIBridge$a is defined multiple times: E:\Dennis\Desktop\New\android\app\build\intermediates\external_file_lib_dex_archives\debug\out\0_unity-classes.jar:classes.dex, E:\Dennis\Desktop\New\android\app\build\intermediates\external_file_lib_dex_archives\debug\out\1_unity-classes.jar:classes.dex
yasirkula commented 3 years ago

How many unity-classes.jar files are there in the Ionic build folder and the Unity build folder?

LasLamos commented 3 years ago

Ionic Build Folder: One unity-classes.jar in

E:\Dennis\Desktop\New\android\app\libs

And then there are these two: image in

E:\Dennis\Desktop\New\android\app\build\intermediates\external_file_lib_dex_archives\debug\out 

which the error is ponting to.

Unity Build Folder: There are two unity-classes.jar One in

E:\Dennis\Desktop\New\UnityProject\unityLibrary\build\intermediates\aar_libs_directory\debug\libs

the other in

 E:\Dennis\Desktop\New\UnityProject\unityLibrary\libs
yasirkula commented 3 years ago

I'd expect E:\Dennis\Desktop\New\android\app\libs to show up in your project's jniLibs directory in Android Studio. If it does, try removing it from the project. If it doesn't, try deleting the file via file browser.

LasLamos commented 3 years ago

There is no unity-classes.jar in my jnilibs Folder.

But i removed unity-classis.jar from

E:\Dennis\Desktop\New\android\app\libs

and now i can build and launch the app!

I can't launch the unity application yet, but thats some different error im guessing is caused by my unity build options.

Thank you sou much for your help!

yasirkula commented 3 years ago

You are welcome! After finding the error, I'd recommend you to search it in this repository's Issues. If no similar issue exists and you think that the issue is related to Ionic integration, then feel free to create another Issue.