Unity Android : no non-static method with name
10,611
I believe it is because you have not declared your manifest correctly so it is still using the normal UnityPlayerActivity instead of your custom one.
Specifically adding this inside the activity tag in the manifest:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Check out the example that Unity gives here: https://docs.unity3d.com/Manual/AndroidUnityPlayerActivity.html
Related videos on Youtube
Author by
Xie WeiXuan
Updated on May 28, 2022Comments
-
Xie WeiXuan almost 2 years
I am making a Android plugin demo for unity,which when I click the button,it will launch another application.I can build an apk and install it to my device.However,when I click the button,nothing happened but sayings:Unity: AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name='shareToWX'
Here is Android code:
public class WXEntryActivity extends UnityPlayerActivity implements IWXAPIEventHandler { private static final String APP_ID=""; private static final String APP_SECRET=""; private static IWXAPI api; private static final int WXSceneSession=0; private static final int WXSceneTimeLine=1; private static final int WXSceneFavorite=2; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); api= WXAPIFactory.createWXAPI(this,APP_ID,true); api.registerApp(APP_ID); api.handleIntent(getIntent(),this); } public void shareToWX(String text,int scene){ WXWebpageObject webpage=new WXWebpageObject(); webpage.webpageUrl="www.baidu.com"; WXMediaMessage msg =new WXMediaMessage(webpage); msg.title="网页标题"; msg.description="描述"; Bitmap thumb=BitmapFactory.decodeResource(getResources(), R.drawable.test); //msg.thumbData= SendMessageToWX.Req req=new SendMessageToWX.Req(); req.transaction=buildTransaction("webpage"); req.message=msg; switch (scene){ case WXSceneFavorite: req.scene=SendMessageToWX.Req.WXSceneFavorite; break; case WXSceneTimeLine: req.scene=SendMessageToWX.Req.WXSceneTimeline; break; case WXSceneSession: req.scene=SendMessageToWX.Req.WXSceneSession; break; } api.sendReq(req); }
And here is my unity code:
public class test : MonoBehaviour { public GameObject btnObj; // Use this for initialization void Start () { Button button = btnObj.GetComponent<Button>(); button.onClick.AddListener(share); } // Update is called once per frame void Update () { } void share() { AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); jo.Call("shareToWX", "unity test",0); } }
Manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yrgame.wjqpyx"> <application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true"> <activity android:name="com.yrgame.wjqpyx.wxapi.WXEntryActivity"/> </application> </manifest>
Error:
I/Unity: AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name='shareToWX' signature='(Ljava/lang/String;I)V' in class Lcom.unity3d.player.UnityPlayerActivity; java.lang.NoSuchMethodError: no non-static method with name='shareToWX' signature='(Ljava/lang/String;I)V' in class Lcom.unity3d.player.UnityPlayerActivity; at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source) 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:136) at com.unity3d.player.UnityPlayer$c.run(Unknown Source) at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0 at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (IntPtr clazz, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0 at UnityEngine.AndroidReflection.GetMetho
Please give me a hand!!!
-
Thaina Yu over 6 yearsCould you first check that your
jo
is really has a typeWXEntryActivity
. Maybe callingjo.Call<AndroidJavaClass>("getClass").Call<string>("toString")
-
-
Lotan about 4 yearsI've the correct manifest (as you point it) and I've stilling the same issue, any idea?