Open Terminal ~/Library/Android/sdk/platform-tools/adb shell ps | grep <com.xxx.xxx> to get the pid of the packagname application And open android studio On logcat section tick on the pull down menu of regex Select Edit Filter Configuration and insert pid, PS: using package name to search is not work well with non-compiled project via android studio.
4)open android terminal first time use Gradle have to change the permission chmod +x gradlew ./gradlew compileDebugSource –stacktrace -info then see the error for details
Change apply plugin: ‘com.android.application’ to apply plugin: ‘com.android.library’
and del applicationid
Go to Gradle Windows > select the package >tasks > Build > assemble
Then it will generate a aar file to this folder xxx\testUnityPackage\app\build\outputs\aar
Then change the file extension to zip
use winrar to open it and del the classes.jar and change back to aar extension
Then the aar file is ready for unity. Open a new project in unity create new button
create new empty game object and add component > new script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class controller : MonoBehaviour {
public Button loginBtn;
// Use this for initialization
void Start () {
loginBtn.onClick.AddListener(loginAction);
}
// Update is called once per frame
void Update () {
}
void loginAction()
{
Debug.Log("You have clicked the button!");
using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"))
{
jo.Call("ShowToast", "Unity use Android's AlertDialog");
}
}
}
}
then go to assets windows create folder Plugins>Android put the aar file and AndroidManifest.xml to the folder
and most important thing is since we have use com.android.support:appcompat-v7 in android studio and we are using gradle method to import the lib, unity will not auto import that library, so we have to copy the v7 lib to the unity, which is location at C:\Users\xxx\AppData\Local\Android\sdk\extras\android\m2repository\com\android\support\appcompat-v7\xxx.aar
Unity go to build setting=>Android=>PlayerSetting change the package name, it should be as same as your android studio aar project
Recent Comments