java - setContentView is not working with GoogleApiClient on release apk -
i've implemented google play games api in game recently, issues appeared after that.
the problem reason game not loading custom view class when start aplication , call method setcontentview() happens when build release version of apk.
gv = new gameview(this); setcontentview(gv); //not loading on release version or if debuggable set true in build.gradle
i tryied put line on build.gradle
debuggable false
the result release version started working line cant upload playstore , reason of thread obviusly because need working on playstore.
some notes of test:
- the google play services connects both release , debug apks, in release black screen appears isntead of gameview class
- the setcontentview() doesn't works when running apk on release version or if debuggable set true in build.gradle.
- the setcontentview() works fine when running apk on debug version
- the setcontentview() works fine if load xml file in situations (but game doesnt uses xmls).
main activity class
public class main extends activity implements googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener { gameview gv; public static dbhandler db; public static string version = "0.0.0"; public static googleapiclient mgoogleapiclient; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); fullscreen(true); //pre estabelece o tamanho da tela deixando no fullscreen primeiramente (toast.maketext(this, "inicializando gameview", toast.length_short)).show(); gv = new gameview(this); setcontentview(gv); // create google api client access play games services mgoogleapiclient = new googleapiclient.builder(this) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .addapi(games.api).addscope(games.scope_games) // add other apis , scopes here needed .setviewforpopups(gv) .build(); // ... //setcontentview(r.layout.loading_screen); db = new dbhandler(this); log.w("main", ""+db.getpointscount()+" - registros encontrados."); //versao --- packageinfo pinfo = null; try { pinfo = getpackagemanager().getpackageinfo(getpackagename(), 0); version = pinfo.versionname; } catch (packagemanager.namenotfoundexception e) { e.printstacktrace(); }// ... } protected void ondestroy(){ super.ondestroy(); gv.relase(); } @override public void onwindowfocuschanged(boolean hasfocus) { super.onwindowfocuschanged(hasfocus); fullscreen(hasfocus); } void fullscreen(boolean hasfocus){ if (hasfocus) { final view decorview = getwindow().getdecorview(); decorview.setsystemuivisibility( view.system_ui_flag_layout_stable | view.system_ui_flag_layout_hide_navigation | view.system_ui_flag_hide_navigation | view.system_ui_flag_fullscreen | view.system_ui_flag_layout_fullscreen | view.system_ui_flag_immersive_sticky);} } @override protected void onstart() { super.onstart(); mgoogleapiclient.connect(); log.e("main","conectando ao google play..."); } @override protected void onstop() { super.onstop(); mgoogleapiclient.disconnect(); log.e("main","desconectado da google api playgames!"); } @override public void onconnected(@nullable bundle bundle) { log.e("main","onconnected"); games.achievements.unlock(mgoogleapiclient, "cgki8au7i4oueaiqag"); (toast.maketext(this, "conectado ao google play game", toast.length_short)).show(); } @override public void onconnectionsuspended(int i) { log.e("main","onconnectionsuspended"); } @override public void onconnectionfailed(@nonnull connectionresult connectionresult) { log.e("main","onconnectionfailed"); (toast.maketext(this, "não foi posivel conectar ao google play services.", toast.length_short)).show(); } }
build.gradle
apply plugin: 'com.android.application' android { signingconfigs { dannarkkey { keyalias 'dannark' keypassword '23021994' storefile file('c:/users/daniel/androidstudioprojects/dannarkkey.jks') storepassword '23021994' } } compilesdkversion 23 buildtoolsversion "21.1.2" defaultconfig { applicationid "com.jumpers.gamelogic" minsdkversion 14 targetsdkversion 21 versioncode 24 versionname "2.7.4" } buildtypes { release { debuggable false minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(include: ['*.jar'], dir: 'libs') testcompile 'junit:junit:4.12' compile 'com.google.android.gms:play-services:9.0.0' }
gameview.class
/** * created daniel on 19/03/2016. */ public class gameview extends view implements runnable { context context; private static final int interval = 10; private boolean running = true; private paint p; public static hud hud; public static printtext pt; public static arraylist<spawnmessagewindows> spawnmsgs = new arraylist<>(); public static scorescreen scorescreen; public static handleeventstouchsspawnedobjects handleeventstouchs = new handleeventstouchsspawnedobjects(); public static load load; public static fase fase; public static player player; public static menu menu; public static camera cam; bitmap layerimg2; public static canvas layer2; public static latercanvas latercanvas; public static int lar; public static int alt; public static int touchfocus = 0; public static arraylist<string> variaveisname = new arraylist<>(); public static arraylist<float> variaveisvalue = new arraylist<>(); private long pretime = 0; public static int timeingame = 0; public static boolean isplaying = false; // blocksidsusedfortutorial tem o objetivo de mostrar menssagens de tutorias pela primeira ves caso vc nunca tenha usado // um script, se tiver dentro dessa lista, entÃo mensagem nao aparecera. public static arraylist<integer> blocksidsusedfortutorial = new arraylist<>(); public gameview(context context) { super(context); this.context = context; load = new load(context); p = new paint(); thread t = new thread(this); t.setpriority(thread.min_priority); t.start(); pretime = system.currenttimemillis()/1000; addvariavel("variavel1", 0); //teste addvariavel("valor3", 0); //teste addvariavel("valor4", 0); //teste addvariavel("valor5", 0); //teste addvariavel("valor6", 0); //teste addvariavel("valor7", 0); //teste addvariavel("valor8", 0); //teste } void init(){ while (getwidth() == 0){ }//aguarndando getwidth lar = getwidth(); alt = getheight(); player = new player(); fase = new tutorial_001(context);//new fase1(context); hud = new hud(); pt = new printtext(); menu = new menu(context); cam = new camera(getwidth(), getheight(), player); layerimg2 = bitmap.createbitmap(lar, alt, bitmap.config.argb_8888); layer2 = new canvas(layerimg2); latercanvas = new latercanvas(context); setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { //int action = event.getactionmasked(); textkeyboard.handletouch(v, event); numerickeyboard.handletouch(v, event); hud.handletouch(v, event); menu.handletouch(v, event); cam.handletouch(v, event); handleeventstouchs.handletouch(v, event); //segura todos os eventos de objetos criados posteiormente return true; } }); } @override public void run() { init(); while (running){ try { thread.sleep(interval); }catch (exception e){ toast t = toast.maketext(getcontext(), "game loop:"+e.getmessage(), toast.length_long); t.show(); log.e("gamelogic", "gameloop erro inesperado: "+e.getmessage()); } update(); } } public void update(){ //dispara o metodo de desenho postinvalidate(); timeingame = (int)((system.currenttimemillis()/1000)-pretime); //tempo jogado em segundos } public void draw(canvas c){ super.draw(c); if(c!=null && player != null && hud != null && menu != null && cam!=null) { c.drawcolor(color.black); if(isplaying) { cam.draw(c, p); hud.draw(c, p); pt.draw(c, p); if(scorescreen != null) { scorescreen.draw(c); } latercanvas.drawbeforemsgs(c); //desenha todos os desenhos sobrepostos na mesma canvas. if(spawnmsgs.size() > 0){ spawnmsgs.get(0).draw(c, p); } latercanvas.drawaftermsgs(c); //desenha todos os desenhos sobrepostos na mesma canvas. //c.drawbitmap(layerimg2,0,0,p); }else { menu.draw(c, p); } } } public void relase(){ running = false; } public static void addvariavel(string variavelnome, float variavelvalor){ if(variaveisname.contains(variavelnome) == false) { variaveisname.add(variavelnome); variaveisvalue.add(variavelvalor); } } public static void removevariavel(int index){ variaveisname.remove(index); variaveisvalue.remove(index); } public static void setvariavelvalor(int valiavelindex, float variavelvalor){ variaveisvalue.set(valiavelindex, variavelvalor); } }
Comments
Post a Comment