Issue
I stuck with a problem. This QUESTION already asked by someone. But there is no answer to this question.
href="https://drive.google.com/open?id=1F4y-QH50eIkAtlbJnlRQ-ze1_2IS2yiz" rel="nofollow noreferrer">Problem Related Video
As per the title of this question. How to integrate multiple unity modules or libraries in the native android project. I have followed lots of procedures. But I did not get the solution to this problem. As per the UNITY TECHNOLOGY instruction I have to integrate the unity library in my project. And I have complete this for two unityLibrary. For the second library, I have to change the package and class name. And make it to work. After doing all these changes my project is building successful and it's compiling without any error. When I am clicking to load the first game then it's loading the first game. But when I click to load the second game then also it's loading the first game only.
Below is the capture screen of my android studio.
I am sharing you the little more description about this.
*Inside app module
there is 2 Activity
, Which is named as MainActivity
and GameHolderActivity
. Below is the code of MainActivity.java
.
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn1Click).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, GameHolderActivity.class);
intent.putExtra("game", 1);
startActivity(intent);
}
});
findViewById(R.id.btn2Click).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, GameHolderActivity.class);
intent.putExtra("game", 2);
startActivity(intent);
}
});
}
}
After that, Now I am mentioning the code for GameHolderActivity.java
.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
//FIRST GAME ACTIVITY
import com.unity3d.player.UnityPlayerActivity;
//SECOND GAME ACTIVITY
import com.game.player.GamePlayerActivity;
public class GameHolderActivity extends Activity {
private String TAG = "GAME_HOLDER_ACTIVITY";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_game);
if (getIntent().hasExtra("game") && getIntent().getIntExtra("game", 0) == 1) {
Log.d(TAG, "FIRST_GAME");
Intent intent = new Intent(GameHolderActivity.this, UnityPlayerActivity.class);
startActivity(intent);
} else {
Log.d(TAG, "SECOND_GAME");
Intent intent = new Intent(GameHolderActivity.this, GamePlayerActivity.class);
startActivity(intent);
}
}
}
Into this entire process I have only change the one library package name. So that I can identify the my second game activity.
And I have add one more thing inside my build.gradle(Module:app)
inside android {}
.
packagingOptions {
pickFirst '**/*.so'
}
I have tried the following tutorial for this but did not get any positive response for multiple games.
So please provide me the solution, So that I can open my both Unity games on my native android application. I will be very thankful for this help.
Solution
Developers. If you are suffering from the problem with this question. Then I would like to tell you that Unity Technology is not supporting this.
So in conclusion, you can not use multiple unityLibrary in your Native android application.
Then how can we achieve our goals?
Regarding this, I have consulted with experts and I have also done my research and communicated with the Unity Support Team as well. For achieving our goals, we have to make a single library for all the games. It means that we have to bind all the games into a single project. And after that we will send some identifiers from the android side to the Unity side. So that we can identify, Which game we have to play. Then after validating, from the unity side we will load that particular scene or game. Like that we can play multiple games as per your requirement.
Answered By - Pushpendra
Answer Checked By - Gilberto Lyons (JavaFixing Admin)