The story that .java is also built in Unity 2018

Looking at the release notes for Unity 2018.2 Functions that I found useful though they weren't introduced on other sites

image.png Android: Added support for using Java source files as plugins in Unity projects. These files are compiled and included in the APK.

If you put the source code like a plugin for iOS, you don't have to create .aar and .jar one by one.

Does that mean?

It was troublesome to set the package name soberly and it was troublesome to base it on. I wonder if this will make it easier (?)

Try Gatten

Export once for Android image.png

Copy src / main / AndroidManifest.xml from the folder you exported to Assets / Plugins / Android image.png

In the same folder https://docs.unity3d.com/Manual/AndroidUnityPlayerActivity.html Make the same thing as

It's not tasteful if it's just that, so put it in toast

python


package [own professional package name];
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;← Add

public class OverrideExample extends UnityPlayerActivity {
  protected void onCreate(Bundle savedInstanceState) {
    // call UnityPlayerActivity.onCreate()
    super.onCreate(savedInstanceState);
    // print debug message to logcat
    Log.d("OverrideActivity", "onCreate called!");
  }
  public void onBackPressed()
  {
    Toast.makeText(this, "test", Toast.LENGTH_LONG).show();← Add
  }
}

Just output the log at startup and display the toast with the back key.

Open AndroidManifest.xml when deployment is complete There is <activity android: label = "@ string / app_name" ~~ around the 5th line, and behind that

android:name="[Package name].UnityPlayerActivity">

Because there is

android:name=".OverrideExample">

change to OverrideExample is a java class name

And build normally

Transfer to the actual machine and press the back key to display the toast! image.png

By the way The Plugins folder is not directly under Assets Note that it will not work properly if the Manifest format is strange. Also be careful because the package of java code is wrong.

end

After all, I have to put the package name in the source, so it seems difficult to separate it completely as a base. However, there seems to be no problem if you build after replacing only that part with the package name in the editor extension.

This is a really helpful feature because it was a hassle to make a jar.

Recommended Posts

The story that .java is also built in Unity 2018
Java Error Handling Basics-The story that catch is only picked up in the foreground
What is the main method in Java?
The story of low-level string comparison in Java
The story of making ordinary Othello in Java
A story about the JDK in the Java 11 era
The intersection type introduced in Java 10 is amazing (?)
The story of learning Java in the first programming
The story that link_to is deep (cause unknown)
[Java] Something is displayed as "-0.0" in the output
[Java] Where is the implementation class of annotation that exists in Bean Validation?
Which is better, Kotlin or Java in the future?
The story that the variable initialization method called in the Java constructor should not be overridden
Java is the 5th day
Determine that the value is a multiple of 〇 in Ruby
Identify threads in the Java process that are wasting CPU
[Docker] The story that an error occurred in docker-compose up
Fixed the phenomenon that vuetify built in Rails is not loaded when page transition is done
Access the network interface in Java
This is the Excel output in Java! "JXLS" official document translation
Java version notation that changes in Java 10
[Gradle] The story that the class file did not exist in the jar file
[Java version] The story of serialization
Specify the java location in eclipse.ini
Like function The part that is stuck in making it asynchronous
Where is the Java LocalDateTime.now () timezone?
The story that standard output also fatally changes the behavior of the program
Unzip the zip file in Java
Parsing the COTOHA API in Java
[Swift] The story that switch is often used for enum judgment
The story that Tomcat suffered from a timeout error in Eclipse
Sample code that uses the Mustache template engine JMustache in Java
Call the super method in Java
A story that addresses the problem that REMOTE_ADDR cannot be acquired in a cluster built with Docker Swarm + Traefik (1.7).
The story of forgetting to close a file in Java and failing
[Java Servlet] The road of Senri is also the fifth step from the first step
[Java Servlet] The road of Senri is also one step to the first
A story about a Spring Boot project written in Java that supports Kotlin
[Java] The story that the expected array was not obtained by the String.split method.
Memo: [Java] If a file is in the monitored directory, process it.
[Java Servlet] The road of Senri is also the third step from the first step
[Introduction to Java] I tried to summarize the knowledge that I think is essential
[Rails] About the error that the image is not displayed in the production environment
[Java small story] Monitor when a value is added to the List
Sample program that returns the hash value of a file in Java
About the phenomenon that StackOverflowError occurs in processing using Java regular expressions
[Git] The horrifying story of deleting the master branch ~ The answer is in English ~
Review of "strange Java" and Java knowledge that is often forgotten in Java Bronze
[Java Servlet] The road of Senri is also the fourth step from the first step
What is a class in Java language (3 /?)
Get the result of POST in Java
Java reference to understand in the figure
Try using the Stream API in Java
Call the Windows Notification API in Java
Rails refactoring story learned in the field
[Java] Use cryptography in the standard library
Organized memo in the head (Java --Array)
What is a class in Java language (1 /?)
Try calling the CORBA service in Java 11+
What is a class in Java language (2 /?)
The story of AppClip support in Anyca