2017-08-25 76 views
0

我试图用this plugin打开一个android图像选择器,但它启动时发生错误。Unity未打开插件活动,包似乎不正确

调用脚本:

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 

看来,这个问题是团结,是在前面加上我的包到包的插件,导致它不被发现。我试图将我的软件包更改为插件的包,但它仍然有相同的错误。

我已经尝试重新安装应用程序,仍然无法打开图库。

回答

0

我发现问题是所有的插件文件都放在了一个子目录中,所以统一无法找到AndroidManifest.xml。将所有项目移出子目录后,画廊打开。

作为一个说明任何人复制上面的代码,然后我发现了一个不相关的错误,image.material.mainTexture = AndroidGallery.Instance.GetTexture();image.sprite = AndroidGallery.Instance.GetSprite();