gpt4 book ai didi

c# - 合并多个 AndroidManifest.xml 时出现问题

转载 作者:太空狗 更新时间:2023-10-29 14:42:44 24 4
gpt4 key购买 nike

我正在开发一个在 Android 上运行的 Unity 应用程序(我们称之为应用程序 A)。我必须将一些代码从另一个 Android Unity 应用程序 (App B) 移到我的 Unity 应用程序中。

我需要移至 App A 的这段代码负责查询 IMU(内部测量单元)。这是App B中存在的相关代码

AndroidJavaObject ActivityObject;
AndroidJavaClass ActivityClass;

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

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

这是 App B 的 list 文件

<?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>

这是 App A 的 list

<?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>

我需要将 App B 的 list 的相关部分复制到 App A 的 list 中,这就是我遇到困难的地方。

所以在 App A 中,有一个辅助线程。这个线程的存在是为了让我们的应用程序可以在应用程序置于后台时进行一些处理。该线程已存在很长时间,当 App A 被置于后台时,尽职尽责地继续执行。

我确实尝试了各种方法来将 list 文件合并在一起。我尝试的第一件事是将 Activity 合并为一个。我发现,除非该 Activity 名为“com.unity3d.player.UnityPlayerNativeActivity”,否则当应用程序置于后台时,我的后台线程不会运行。

这是我最近尝试的 list 。

<?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>

有了这个 list ,我的线程在后台运行得很好,但是这段代码

  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");

产生这个输出。

At pos 1 At pos 2 ActivityClass != null At pos 3
AndroidJavaException: java.lang.NoSuchFieldError: no "Ljava/lang/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) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:145) at com.unity3d.player.UnityPlayer$c.run(Unknown Source) at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in :0 at UnityEngine.AndroidJNISafe.GetStaticFieldID (IntPtr clazz, System.String name, System.String sig) [0x00000] in :0 at UnityEngine._AndroidJNIHelper.GetFieldID (IntPtr jclass, System.String fieldName, System.String signature, Boolean isStatic) [0x00000]

如能深入了解我需要做什么才能使这项工作正常进行,我们将不胜感激。

谢谢约翰·劳里

最佳答案

正如错误所述,您的 com.indotraq.android.rtls.MainActivity 中没有“currentActivity”字段类(class)。 currentActivitycom.unity3d.player.UnityPlayer 的成员.您可以在类中创建一个静态字段,然后在 MainActivity 的构造函数中自行分配它。像这样就可以了

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

}

然后就可以成功调用非静态方法tagID = ActivityObject.Call<string>("getTAGID");

PS:它实际上并没有获得“Activity ”,只是类的实例,currentInstance会更合适。

关于c# - 合并多个 AndroidManifest.xml 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45231345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com