How to import unity project into existing Android studios projecT? - android-studio

I am having problems importing unity project into Android Studios. I already have a Android studio project (for menu and other things), and i want to add a scene from Unity 5 3D, as a second activity (not the main activity).
I want to call unity scene when user clicks the button.
I know how to export it from unity but it automatically sets it as MainActivity, and i cant find a way to manually overwrite it.
Edit:
I want to do it in Android Studios and not Eclipse. I just want to know if there is an easy way to do it, or at least a hint for how to do it.

Had the same requirement and successfully imported the Unity project into an existing Android Studio project. As mentioned the first thing will be to export the Unity project. I used Unity version 2017.1. Rough steps below:
Export Android project via Unity build settings
You can simply select the folder where your existing project is located. Unity should add a sub folder with an Android Studio format project and all dependencies and everything it needs to run.
Now we need to convert this "Application" project to a "Library" project. This is simply done by changing the build.gradle file. Replace apply plugin: 'com.android.application' with apply plugin: 'com.android.library'.
You also need to remove the applicationId and change the compile versions to match your project's versions.
Also make sure to modify the Unity module AndroidManifest.xml file. You will need to remove the LAUNCHER intent-filter as the UnityPlayerActivity will not be the main activity anymore.
android.intent.action.MAIN
android.intent.category.LAUNCHER
Also need to remove the Application node attributes so it won't conflict with your project's manifest.
Finally in your settings.gradle add the module and then add the Unity project dependency on your "app" module: compile project(':UnityFolder')
Build and now you should be able to start the Unity Scene by calling:
Intent intent = new Intent(this, UnityPlayerActivity.class);
startActivity(intent);

yes we can start another activity before unity Activity
1 step-create java class and add it in manifest and like in image
2nd step- create onClick in java class
link to unity game class s you can see in amage
see pic, you can choose button also
3rd step- in manifest replace Intent in own java class it will work [3]

From this link: https://nevzatarman.com/2015/01/04/unity-android-tutorial-opening-unity-scene-from-an-activity/
Add android:process=":UnityKillsMe" to the unity activity GameActivity.

Related

How to create a standalone android aar library project?

I want to create a project that simply creates an aar library. Everything I see on google is about doing that from an 'existing project' which I do not want. That seems to tie into just that project. When I click new project in android studio, I don't see an option for 'library' and it creates an application every time :(.
How does one simply create a project that creates an aar artifact?
I stumbled upon a workaround since the answer to my question is NO :(. Wow!! Why in the world can you not create a library?
Anyways, the answer on this one is what I do now as it seems the cleanest
How to create new Android AAR in Android Studio

layout resource directory not created automatically when I create android project in android studio

At first when i create my my android project in android studio android studio automatically creates a layout resource directory which contains the activity_main.xml file along with the main.kt file in the java directory.But after creating some few projects, android studio fails to provide me with the layout directory with the activity_main.xml and main.kt files automatically.I'm a beginner with the android studio environment that's why i prefer it comes with the layout resource folder and activity_main folder because I mess up the configurations when i create them by myself and fails to lunch app on my android phone.I would like to know whether there is a way to reverse this problem or i should always create my layout resource directory by my self if so then i would like a demonstration of how to create my main_activity.xml so that i don't mess the configuration.Any help would be appreciated and thanks in advance.
It seems you are looking to create from a template (create activity along with the layout and added the activity in the manifest as well). Please read the docs in here: https://developer.android.com/studio/projects/templates

Can't add a new activity on android studio

I'm trying to improve my android development skills, so working on some project about it. In my project, I added a new "Navigation Drawer Activity", then I deleted it because I wanted to create a new one but I can not able to add even another type of activitiy. Android studio adds ,
<activity
android:name=".ExampleActivity"
android:label="#string/title_activity_main" >
</activity>
tag in AndroidManifest.xml but It doesn't create any classes and xml layout files.
Also studio says:
ide internal error occurred android studio.
I tried regenerate R.java and clean my project ,but it doesn't work. How can I get rid of this problem?
Try to add a simple JavaClass and write an "extends Activity" behind the class name. And put this new Activity in the Manifest like in your example. You can add a menu and a layout like this, too, when you add xml-Files in the layout and menu folders. This should work.
I can not find a exact solution to that problem. Re-installed the Android Studio . It does the solution manually
If it's about how Activities is not showing up as an option in either the shortcut menu in the Layout folder or File + New in the menu, you can try File + "Sync Project with Gradle files" and give it some time.
This also adds options to the Tools menu (great if AVD or SDK Manager is missing).

Facebook SDK not imprted in Android studio

I have downloaded the facebook sdk version 3.21.1 and I have android studio version 1.0.2.
Whenever I try to import the 'facebook' folder in the sdk folder(through the import module method), it dosent show up in the project tree on the left hand pane. Also I am getting this error : Error:(1, 0) Gradle DSL method not found: 'pply()'
Possible causes:The project 'The Social App' may be using a version of Gradle that does not contain the method.
Gradle settingsThe build file may be missing a Gradle plugin.
Apply Gradle plugin
Please help.
For me I was having similar problems.
I am using Android Studio 1.1 and Facebook SDK 4.0.0
First, be sure to follow that steps 3 to 6 in the facebook developers page in your existing project.
Click here for the getting started instructions.
Be very sure you follow it all.
After importing it I didn't see it in my project structure be sure to click down on the left corner and make sure it is on Project, if not use the drop down and select Project.
Also do ctrl+alt+shiftt+s to bring up the project structure wizard. Then go to app dependencies and click plus in the right corner to add the :facebook module dependency.
Then make sure that in your root project build.gradle that it's using gradle 1.1.1 since some problems with importing has been fixed here.
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Then referencing this answer was the finishing touch:
Can not import facebook-sdk 4.0.1
Then a pop should appear to upgrade buildToolsVersions to 21.1.1.
This is what it took for me to get this all working. Hope it works for you too!

Android studio no main activity, no layouts on a new project

I installed new Android Studio. I created new Project and asked the wizard to create main activity. But there were no layouts, no main activity class, no nothing. Error on trying to make new Java class files. The new project tree looks like this:
No (main/java) folder.
No (res/layout) folder.
Other words project is useless.
From what i learned is that you may be picking the "no layout" option when prompted to pick one. Try picking the basic activity and the rest of the files will show
After creating the project, you need to go to File menu and then Import Project. Then browse to the location of your project and import it. Then you will see all of these files and folders. I had this problem too, and it seems to be something that they overlooked in the newer versions of Android Studio (which is quite pathetic if you ask me).
Empty Activity
Choose "Empty Activity" instead of "No Activity",
while creating a NEW PROJECT in Android Studio.
I don't know if anyone is having the same problem right now but i solved this issue by changing the Android Gradle plugin version and the Gradle version.
For doing this you have to open the project you're having issues with and click on
File->Project Structure->Project
and there you will see the two options.
Android Gradle Plugin Version 4.0.0 and Gradle version 6.1.1 worked for me. After that I went to the file directory, right click on the package folder "com.example.myProject" and manually created an empty activity. The layout folder with my new activity was created automatically after that.
I found it's because I changed the Java runtime version before through the Android Studio plugin Choose Runtime. I changed to JDK 8 from JDK 11 then the problem occured. It worked for me to change back to JDK 11 through plugin Choose Runtime.
Try
Typing main activity (without quotes) in the search box and
Press enter.
For me it got restored. Search window is useful in finding many hidden tools quickly.
I created a new activity by right clicking on java then selected activity and the layout file was automatically written
When you open a new project, you can't select "empty project" you have to select and activity project. I just went through this had to delete my project and start a new one now everythings there.

Resources