Problems combining multiple AndroidManifest.xml

I'm working on a Unity app that runs on Android (lets call it App A). I need to move code from another Android Unity app (App B) to my Unity app.

This code, which I need to move to App A, is responsible for the IMU (Internal Measurement Unit) request. This is the relevant code that exists in Appendix B

AndroidJavaObject ActivityObject;
AndroidJavaClass ActivityClass;

AndroidJNI.AttachCurrentThread();
ActivityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
ActivityObject = ActivityClass.GetStatic<AndroidJavaObject>("currentActivity");

tagID = ActivityObject.Call<string>("getTAGID");

      

And here is the manifest file for Application B

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.indotraq.rtls" android:versionName="1.0.0" android:versionCode="1">

  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:debuggable="false">

    <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>

    <activity
            android:name="com.indotraq.android.rtls.MainActivity"
            android:screenOrientation="landscape" 
            android:launchMode="singleTask"
            android:configChanges="screenSize|orientation|keyboardHidden|keyboard"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                 <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/> 
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
             <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" /> 
    </activity>

  </application>

  <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
</manifest>

      

This is the manifest from app A

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sensics.palace" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>
  </application>
  <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
  <uses-feature android:glEsVersion="0x00020000" />
  <supports-gl-texture android:name="GL_AMD_compressed_ATC_texture" />
  <supports-gl-texture android:name="GL_ATI_texture_compression_atitc" />
  <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="android.permission.INTERNET" /> 
</manifest>

      

I need to copy the relevant parts of the manifest for application B into the manifest for application A, and this is where I am stuck.

So there is a secondary thread in Appendix A. This thread exists, so our application can do some processing when the application is pushed into the background. This thread has been around for a long time, and docile launches continue to run when app A is pushed into the background.

I tried different things to combine the manifest files. The first thing I tried was to combine the actions into one. I found that if the activity is not called "com.unity3d.player.UnityPlayerNativeActivity" my background thread would not start when the app was pushed into the background.

This is evident in my last attempt.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.indotraq.rtls" android:versionName="1.0.0" android:versionCode="1">

  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:debuggable="false">

    <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
        </intent-filter>
        <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
        <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" />
    </activity> 
    <activity
            android:name="com.indotraq.android.rtls.MainActivity"
            android:screenOrientation="landscape" 
            android:launchMode="singleTask"
            android:configChanges="screenSize|orientation|keyboardHidden|keyboard"
            android:label="@string/app_name" >
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>
  </application>

  <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
</manifest>

      

With this manifest, my thread runs fine in the background, but this code

  LogManager.Log("At pos 1");
  AndroidJNI.AttachCurrentThread();
  LogManager.Log("At pos 2");
  ActivityClass = new AndroidJavaClass("com.indotraq.android.rtls.MainActivity");

  if(ActivityClass == null) {
    LogManager.Log("ActivityClass == null");
  }
  else {
    LogManager.Log("ActivityClass != null");
  }

  LogManager.Log("At pos 3");
  ActivityObject = ActivityClass.GetStatic<AndroidJavaObject>("currentActivity");
  LogManager.Log("At pos 4");

  tagID = ActivityObject.Call<string>("getTAGID");
  LogManager.Log("At pos 5");

      

Produces this output.

At pos 1 At pos 2 ActivityClass! = Null At pos 3
AndroidJavaException: java.lang.NoSuchFieldError: no "Ljava / languages ​​/ object;" field "currentActivity" in class "Lcom / indotraq / Android / RTLS / MainActivity;" or its superclasses
java.lang.NoSuchFieldError: no "Ljava / lang / Object;" field "currentActivity" in class "Lcom / indotraq / android / rtls / MainActivity;" or its superclasses at com.unity3d.player.UnityPlayer.nativeRender (native method) at com.unity3d.player.UnityPlayer.c (Unknown source) at com.unity3d.player.UnityPlayer $ c $ 1.handleMessage (Unknown source) on android .os.Handler.dispatchMessage (Handler.java:98) on android.os.Looper.loop (Looper.java:145) at com.unity3d.player.UnityPlayer $ c.run (Unknown source) on UnityEngine.AndroidJNISafe.CheckException () [0x00000] at: 0 at UnityEngine.AndroidJNISafe.GetStaticFieldID (IntPtr clazz, System.String name, System.String sig) [0x00000] at: 0 at UnityEngine._AndroidJNIHelper.GetFieldID (IntPtr signature jclass, System.String System.String, Boolean isStatic) [0x00000]

Any insight into what I need to do to get this job would be greatly appreciated.

Thank. John Laurie

+3


source to share


1 answer


As the error says, com.indotraq.android.rtls.MainActivity

there is no currentActivity ' field in the class . currentActivity

is a member com.unity3d.player.UnityPlayer

. You can create a static field in the class and assign it yourself in the MainActivity constructor . Something like this would do

public class MainActivity extends AppCompatActivity
{
  static public MainActivity currentActivity;
  MainActivity()
  {
    currentActivity = this;
  }

}  

      



Then you can successfully call the non-static method tagID = ActivityObject.Call<string>("getTAGID");

PS : it doesn't actually get the "activity", just an instance of the class, so currentInstance

would be more appropriate.

0


source







All Articles