我正在尝试使用this plugin打开Android图片选择器,但启动时会出错。
调用脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using LukeWaffel.AndroidGallery;
public class LoadImageWithMagic : MonoBehaviour {
public Image image;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OpenGallery() {
Debug.Log ("It clicked");
AndroidGallery.Instance.OpenGallery (GalleryCallback);
}
public void GalleryCallback() {
image.material.mainTexture = AndroidGallery.Instance.GetTexture ();
AndroidGallery.Instance.ResetOutput ();
}
}
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application
android:theme="@style/UnityThemeSelector"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<activity android:name= "com.lukewaffel.androidgallery.Gallery"></activity>
</application>
</manifest>
logcat错误:
08-25 09:53:09.029 3458-3474/com.TNOAB.FindMyPet I/Unity: It clicked
(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-25 09:53:09.036 3458-3474/com.TNOAB.FindMyPet I/Unity: [Singleton] An instance of LukeWaffel.AndroidGallery.AndroidGallery is needed in the scene, so '(singleton) LukeWaffel.AndroidGallery.AndroidGallery (UnityEngine.GameObject)' was created with DontDestroyOnLoad.
(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-25 09:53:09.060 1485-1737/system_process I/ActivityManager: START u0 {cmp=com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery} from uid 10061 on display 0
08-25 09:53:09.082 3458-3474/com.TNOAB.FindMyPet I/Unity: AndroidJavaException: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery}; have you declared this activity in your AndroidManifest.xml?
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
at android.app.Activity.startActivityForResult(Activity.java:3745)
at android.app.Activity.startActivityForResult(Activity.java:3706)
at android.app.Activity.startActivity(Activity.java:4016)
at android.app.Activity.startActivity(Activity.java:3984)
at com.lukewaffel.androidgallery.UnityBinder.OpenGallery(UnityBinder.java:12)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.c
看来问题是Unity正在将我的软件包添加到插件的包中,导致无法找到它。我试图将我的包更改为插件的包,但它仍然有同样的错误。
我已尝试重新安装该应用,但仍然无法让图库打开。
答案 0 :(得分:0)
我发现问题是所有的插件文件都放在了一个子目录中,所以Unity找不到AndroidManifest.xml。将所有项目移出子目录后,图库就会打开。
作为复制上述代码的任何人的注释,我随后发现了一个无关的错误,image.material.mainTexture = AndroidGallery.Instance.GetTexture ();
应为image.sprite = AndroidGallery.Instance.GetSprite ();