下面是我的python代码,它成功地工作到了一定程度:
from jnius import autoclass, PythonJavaClass, java_method, cast
from kivy.app import App
import logging
testmode = True
PythonActivity = autoclass("org.kivy.android.PythonActivity")
Unity_ads_listener = autoclass("com.unity3d.ads.IUnityAdsListener")
Unity_ads = autoclass("com.unity3d.ads.UnityAds")
class Unity_handler:
def __init__(self, a_id):
self.app_id = a_id
def init_unity(self):
new_ad_listener = UnityAdsListener()
Unity_ads.addListener(new_ad_listener)
self.c_activity = cast('android.app.Activity',PythonActivity.mActivity)
Unity_ads.initialize(self.c_activity,self.app_id,testmode)
logging.warning("\n Unity ads initialized \n")
def show_ad(self, id_num):
#show interstial ads
self.inter_id = id_num
if Unity_ads.isReady(self.inter_id):
try:
Unity_ads.show(self.c_activity, self.inter_id)
except:
fail=1
class UnityAdsListener(PythonJavaClass):
__javacontext__= 'app'
__javainterfaces__= ['com/unity3d/ads/IUnityAdsListener']
#def __init__(self):
# super(IUnityAdsListener, self).__init__()
# #self.callback = callback
@java_method('(Ljava/lang/String;)V')
def onUnityAdsReady(inter_id):
pass
@java_method('(Ljava/lang/String;)V')
def onUnityAdsStart(inter_id):
pass
@java_method('(Ljava/lang/String;Ljava/lang/String;)V')
def onUnityAdsFinish(inter_id,un_f):
pass
@java_method('(Lcom/unity3d/ads/UnityAds$UnityAdsError;Ljava/lang/String;)V')
def onUnityAdsError(self,error, message):
pass
我展示了这些广告,但经过一段时间的反复展示,很快就崩溃了。我怀疑从java接口继承的java方法可能有问题。这是一份坠机报告:
09-05 16:51:40.775 260 454 d audioflinger \u threads:0xa8603180:threadloop \u write write muted data to hw,mixerstatus 1 start 09-05 16:51:40.778 12274 12274 i python:traceback(最近一次调用):09-05 16:51:40.780 789 840 v windowmanager:looking for focus:8=window{deb1e08 u0 statusbar},flags=-2122055608,canreceive=false 09-05 16:51:40.780 12274 12274 i python:文件“jnius/jnius\u proxy.pxi”,第156行,在jnius.jnius.invoke0 09-05 16:51:40.781 789 840 d windowmanager:notifyactivitydrawnforkeyguard:waiting=false callers=com.android.server.wm.windowsurfaceplacer.handlapptransitionre中adylocked:1227 com.android.server.wm.windowsurfaceplacer.performsurfaceplacementinner:337 com.android.server.wm.windowsurfaceplacer.performsurfaceplacementloop:235 com.android.server.wm.windowsurfaceplacer.performsurfaceplacement:183 com.android.server.wm.windowmanagerservice$h.手lemessage:8417 09-05 16:51:40.781 12274 12274 i python:文件“jnius/jnius\u proxy.pxi”,第124行,在jnius.jnius.py\u invoke0 09-05 16:51:40.781 789 840 v windowmanager:查找焦点:8=window{deb1e08 u0 statusbar},标志=-2122055608,canreceive=false 09-05 16:51:40.782 12274 12274 i python:attributeerror:'kivy.core.text.text\u layout.layoutword'对象没有属性'invoke'09-05 16:51:40.783 12274 12274 d androidruntime:关闭vm 09-05 16:51:40.786 789 840 i活动管理器:显示com.oracle.oracle/com.unity3d.services.ads.adunit活动:+166ms 09-0516:51:40.787 789 882 i libperfservice:1:set:3 09-05 16:51:40.787 789 882 i libperfservice:1:set freq:819000 09-05 16:51:40.792 12274 12274 e androidruntime:致命异常:main 09-05 16:51:40.792 12274 12274 e androidruntime:进程:com.oracle.oracle,pid:12274 09-05 16:51:40.792 12274 12274 e androidruntime:java.lang.nullpointerexception:应取消“int”基元类型的装箱,但返回null 09-05 16:51:40.792 12274 12274 e androidruntime:at$proxy0。哈希代码(未知源)09-05 16:51:40.792 12274 12274 e androidruntime:atsun.misc.hashing.singlewordwangjenkinshash(哈希)。java:48)09-05 16:51:40.792 12274 12274 e androidruntime:在java.util.hashmap.put(hashmap。java:423)09-05 16:51:40.792 12274 12274 e androidruntime:位于java.util.hashset.add(hashset。java:217)09-05 16:51:40.792 12274 12274东安德罗尼时间:atjava.util.abstractcollection.addall(抽象集合。java:342)09-05 16:51:40.792 12274 12274 e androidruntime:位于java.util.linkedhashset.(linkedhashset。java:169)09-05 16:51:40.792 12274 12274 e androidruntime:网址:com.unity3d.ads.properties.adsproperties.getlisteners(adsproperties)。java:47)09-05 16:51:40.792 12274 12274东安德罗尼时间:atcom.unity3d.services.ads.api.listener$5.run(listener。java:76)09-05 16:51:40.792 12274 12274 e androidruntime:在android.os.handler.handlecallback(handler。java:836)09-05 16:51:40.792 12274 12274 e androidruntime:在android.os.handler.dispatchmessage(handler。java:103)09-05 16:51:40.792 12274 12274东安德罗尼时间:atandroid.os.looper.loop(looper。java:203)09-05 16:51:40.792 12274 12274 e androidruntime:at android.app.activitythread.main(活动线程)。java:6251)09-05 16:51:40.792 12274 12274 e androidruntime:at java.lang.reflect.method.invoke(本机方法)09-05 16:51:40.792 12274 12274 e androidruntime:atcom.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit。java:1063)09-05 16:51:40.792 12274 12274 e androidruntime:网址:com.android.internal.os.zygoteinit.main(zygoteinit。java:924)09-05 16:51:40.796 789 976 w活动管理器:force finishing activity com.oracle.oracle/com.unity3d.services.adunit.adunitivity
暂无答案!
目前还没有任何答案,快来回答吧!