Looking at the release notes for Unity 2018.2 Functions that I found useful though they weren't introduced on other sites
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 (?)
Export once for Android
Copy src / main / AndroidManifest.xml from the folder you exported to Assets / Plugins / Android
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!
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.
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