Integrating two Unity projects in an Android application - android

I'm developing an Android app and I need to integrate Unity games/screens in it. I've already exported and added one Unity scene/project to my android app but I cannot figure out how to add two.
I found two main approaches to this:
Create two separate projects: If I do this they clash either in the manifest or in the libraries/assets folder and unity ends up calling just one scene.
For reference:
How to correctly import multiple unity module in single android app avoiding name conflict between different unity module in android studio?
I also tried creating one Unity project with multiple scenes and use messages to call the required scene from Android. For me, Android still calls the same scene regardless of which button is pressed.
Reference:
https://stackoverflow.com/a/43224821/2617578
Does anyone have a solution for this? Either one of the solutions mentioned above would be okay for me.
I'm experienced in Android but a beginner in Unity so I think I might be doing something wrong in the unity code.
I have the unity projects and Android apps I created for the second approach in the following git repository.
https://github.com/hadi-mehmood/AndroidUnityIntegrationSample

Here is one solution to your problem:
First, All things happen inside unity are in one activity.
Combine two unity projects and make different scenes for each of them
create a empty loading scene that starts first (using unity BuildSettings) and does not do anything
on the loading scene, write a SceneLoader script to wait for a command to load a minigame scene.
you can pass the scene name using this method UnityPlayer. UnitySendMessage("Gameobject Name","Method","Message")
right after running Unity Activity call the method above and it should do the work.
Sample SceneLoader:
public class MySceneLoader : MonoBehaviour
{
private void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
}
}

Related

Is there a way to add a complex flutter app with flutter_storyBook as a module for a native Kotlin App?

I have a very complex flutter app with story book and everything, and I'd like to reuse the code inside my native Kotlin app, but it's a lot of screens, login and everything, and it has flutter_storybook
I've tried following the flutter docs tutorial for integrating as a module (considering just my main.dart as entry point), but I ended stuck with a black screen everytime I try to launch de FlutterActivity, is there anything more I need to do????

Import Unity Classes into Existing Android Project

As the title says, I have an existing Android project and I want to import Unity classes.jar so I can access the UnityPlayer.UnitySendMessage.
I found this other question with similar goal, but the answers were unintelligible or unhelpful.
I also found this on the Unity forums, but it is apparently very outdated (2011).
Essentially, all I'm trying to do is:
Open up an Android application.
Select which scene (or, preferably, more than one scene) I want to view from the Unity app.
Launch the Unity GearVR application.
Play the selected scene(s).
I've already got steps 1 and 3 working, and steps 2 and 4 I'm making work by loading each scene up as a different APK and launching a specific APK depending on which scene I want to view, but, ideally, I could host all the scenes in a single application so I could then watch several off the scenes in a row (and also so I could cut down significantly on memory usage).
I've found some tutorials on using UnityPlayer.UnitySendMessage, so I think I can get it working if I can only get Android Studio to recognize and use UnityPlayer.UnitySendMessage, but if you have any other ideas, I appreciate those as well!
I've found some tutorials on using UnityPlayer.UnitySendMessage, so I
think I can get it working if I can only get Android Studio to
recognize and use UnityPlayer.UnitySendMessage
Get classes.jar from one of the sub-folders from
<UnityInstallationDirectory>\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono
or
<UnityInstallationDirectory>\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\il2cpp
depending on if you are using mono or IL2CPP as Scripting Backend to build your Android Project.
Import it into Android Studio. Right-click on it and click Add As library and Android Studio should add it as library. See this if you are still confused. You can now use UnityPlayer.UnitySendMessage.
As for the rest of your question, I think that you should look into this answer. It explains how you can show Unity scene in a sub-view. That is another way to get what you want.

Combining several android applications together

I am working on an android group project in college and this is the first big project many of us have worked on.
We worked on implementing several pieces of the project as completely separate projects and now are having trouble putting all of them in one application with a main page.
On the main page of the application we would have a bunch of buttons that would then go to the implemented project that we've completed (example, I click on BMI calculator on the app homepage and it goes the the bmi calculator screen).
Any efficient way of going about this that can be explained in an easy to follow manner? I'm still a newbie programmer :)
Just to clarify, I don't want it so that it just launches a BMI calculator app from the main app, the entire code base is supposed to exist under one app.
Thanks
You can have a main project and several other projects declared as library projects.
In build time, library projects are pulled into the main project and only one apk will exist as the output.
The library projects are almost the same as an usual android project. You can have java packages, res folder, lib folder, etc.
Check here for the official description.
Check here for a tutorial.
Look into making the other applications as Android Library-projects, and listing all necessary components on your AndroidManifest.xml on your parent project.
Another way would just give the option for the user to install these applications as separate and have a logice (PackageManager) check if specific application exists or is installed and then enabling navigation buttons or disabling components and invoke them via Intents.

UnsatisfiedLinkError using Box2d libgdx for android

I am trying to use the libGDX box2d wrapper, but I do not want to use the the full libGDX game engine, because I already have my game implemented and now I want to add some physics.
So, I downloaded the libGDX libraries and put them in build path.
I see the following error:
UnsatisfiedLinkError at com.badlogic.gdx.physics.box2d.World.newWorld(Native Method)
at com.badlogic.gdx.physics.box2d.World.<init>(World.java:101)
at org.anddev.andengine.extension.physics.box2d.PhysicsWorld.<init>(PhysicsWorld.java:61)
at org.anddev.andengine.extension.physics.box2d.PhysicsWorld.<init>(PhysicsWorld.java:57)
What can I do?
I use this code from google discussion and it's working fine at my side.
import com.badlogic.gdx.utils.GdxNativesLoader;
GdxNativesLoader.load();
Use this before you do anything. make sure you have gdx.jar and gdx-natives.jar in your project.
This error will happen if you assign an instance during a World property declaration, keeping an empty declaration and assigning the new instance on the App create() method should fix it.

libgdx and TWL: Android app force closes on any TWL menu, works fine on Desktop

I am implementing menus using TWL (http://twl.l33tlabs.org/) in an app written using Libgdx. The app runs fine if I don't start any menus, but as soon as I go to a menu screen it immediately force-closes. Menu screens work fine on the desktop version.
In which build path should TWL-android.jar be included (right now it behaves the same in main, android, and both)? And how will the program know to use the libraries from this .jar instead of the default gdx-twl.jar? Will I have to manually implement something in code to use one or the other depending on platform?
There does not seem to be any documentation or sample code of anyone using TWL on android, only mentioning that it can be done.
Running debugger attached to phone gives the following logcat error:
Could not find class 'com.badlogic.gdt.twl.Layout' referenced from method com.Nanners.OptionsScreen.<init>
I think that TWL-android.jar should be added to android project's build path too. Location of .jar is not relevant.
When you add TWL-android.jar. As that is Android specific you can't use it on the core project, so the classes you are importing are the ones from gdx-twl. To make it simpler to explain I will divide it in different escenarios.
You add TWL-android to your Android buildpath. But you use Gdx-twl in your core project. Which isn't added. Thus getting a:
Could not find class 'com.badlogic.gdx.twl.Layout'
You add both TWL-android AND Gdx-twl to your build path. Thus getting duplicated classes and:
Conversion to Dalvik format failed with error 1
Solution
If you use TWL-android classes, you can only do it inside the Android project:
Merge Core, Desktop and Android project. Or
Use Interfacing with Platform Specific
If you use Gdx-twl:
Don't do it.
Actually the best solution is to get rid of all twl stuff and use Scene2d.Ui instead. Its crossplatform and much easier to use.

Categories

Resources