2016-02-12 53 views
2

我正在使用Intellij。一切工作正常,並且APK部署在我的Android,但它只是停留黑屏,回到家裏說,「‘遊戲’停止:LibGdx [致命例外]加載皮膚.json文件

1023-1051/? E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 1591 
Process: net.mygdx.game.android, PID: 1023 
com.badlogic.gdx.utils.ax: Error reading file: jsonSkin.json 
     at com.badlogic.gdx.e.a.a.i.a(Unknown Source) 
     at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source) 
     at net.mygdx.game.a.a(Unknown Source) 
     at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source) 
     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520) 
     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) 
Caused by: com.badlogic.gdx.utils.ax: Error reading file: skins/jsonSkin.json 
     at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source) 
      at org.mygdx.gam.a.a(Unknown Source) 
      at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source) 
      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520) 
      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) 
Caused by: com.badlogic.gdx.utils.ax: 
     at com.badlogic.gdx.e.a.a.k.a(Unknown Source) 
     at com.badlogic.gdx.e.a.a.k.b(Unknown Source) 
     at com.badlogic.gdx.utils.k.a(Unknown Source) 
     at com.badlogic.gdx.e.a.a.j.a(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source) 
      at net.mygdx.game.a.a(Unknown Source) 
      at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source) 
      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520) 
      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) 
Caused by: com.badlogic.gdx.utils.b.e: Class not found: com.badlogic.gdx.graphics.g2d.BitmapFont 
     at com.badlogic.gdx.utils.b.b.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.k.b(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.j.a(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source) 
      at net.mygdx.game.a.a(Unknown Source) 
      at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source) 
      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520) 
      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) 
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.graphics.g2d.BitmapFont 
     at java.lang.Class.classForName(Native Method) 
     at java.lang.Class.forName(Class.java:251) 
     at java.lang.Class.forName(Class.java:216) 
      at com.badlogic.gdx.utils.b.b.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.k.b(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.j.a(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source) 
      at net.mygdx.game.a.a(Unknown Source) 
      at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source) 
      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520) 
      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) 
Caused by: java.lang.NoClassDefFoundError: com/badlogic/gdx/graphics/g2d/BitmapFont 
      at java.lang.Class.classForName(Native Method) 
      at java.lang.Class.forName(Class.java:251) 
      at java.lang.Class.forName(Class.java:216) 
      at com.badlogic.gdx.utils.b.b.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.k.b(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.j.a(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source) 
      at org.mygdx.gam.a.a(Unknown Source) 
      at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source) 
      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520) 
      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.badlogic.gdx.graphics.g2d.BitmapFont" on path: DexPathList[[zip file "/data/app/org.mygdx.gam.android-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.mygdx.gam.android-1, /vendor/lib, /system/lib]] 
     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:497) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 
      at java.lang.Class.classForName(Native Method) 
      at java.lang.Class.forName(Class.java:251) 
      at java.lang.Class.forName(Class.java:216) 
      at com.badlogic.gdx.utils.b.b.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.k.b(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.j.a(Unknown Source) 
      at com.badlogic.gdx.utils.k.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.a(Unknown Source) 
      at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source) 
      at org.mygdx.gam.a.a(Unknown Source) 
      at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source) 
      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520) 
      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) 

這對是我以.json文件;

{ 
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } }, 
com.badlogic.gdx.graphics.Color: { 
    green: { a: 1, b: 0, g: 1, r: 0 }, 
    white: { a: 1, b: 1, g: 1, r: 1 }, 
    red: { a: 1, b: 0, g: 0, r: 1 }, 
    black: { a: 1, b: 0, g: 0, r: 0 }, 
}, 
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: { 
    dialogDim: { name: white, color: { r: 0, g: 0, b: 0, a: 0.45 } }, 
}, 
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: { 
    default: { down: default-round-down, up: default-round }, 
    toggle: { down: default-round-down, checked: default-round-down, up: default-round } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: { 
    default: { down: default-round-down, up: default-round, font: default-font, fontColor: white }, 
    toggle: { down: default-round-down, up: default-round, checked: default-round-down, font: default-font, fontColor: white, downFontColor: red } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: { 
    default: { vScroll: default-scroll, hScrollKnob: default-round-large, background: default-rect, hScroll: default-scroll, vScrollKnob: default-round-large } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: { 
    default: { 
     font: default-font, fontColor: white, background: default-select, 
     scrollStyle: default, 
     listStyle: { font: default-font, selection: default-select-selection } 
    } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.SplitPane$SplitPaneStyle: { 
    default-vertical: { handle: default-splitpane-vertical }, 
    default-horizontal: { handle: default-splitpane } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: { 
    default: { titleFont: default-font, background: default-window, titleFontColor: white }, 
    dialog: { titleFont: default-font, background: default-window, titleFontColor: white, stageBackground: dialogDim } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.ProgressBar$ProgressBarStyle: { 
    default-horizontal: { background: default-slider, knob: default-slider-knob }, 
    default-vertical: { background: default-slider, knob: default-round-large } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: { 
    default-horizontal: { background: default-slider, knob: default-slider-knob }, 
    default-vertical: { background: default-slider, knob: default-round-large } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: { 
    default: { font: default-font, fontColor: white } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: { 
    default: { selection: selection, background: textfield, font: default-font, fontColor: white, cursor: cursor } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.CheckBox$CheckBoxStyle: { 
    default: { checkboxOn: check-on, checkboxOff: check-off, font: default-font, fontColor: white } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: { 
    default: { fontColorUnselected: white, selection: selection, fontColorSelected: white, font: default-font } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.Touchpad$TouchpadStyle: { 
    default: { background: default-pane, knob: default-round-large } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.Tree$TreeStyle: { 
    default: { minus: tree-minus, plus: tree-plus, selection: default-select-selection } 
}, 
com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle: { 
    default: { 
     label: { font: default-font, fontColor: white }, 
     background: default-pane, wrapWidth: 150 
    } 
}, 
} 

而且這些線是誰是怪異的,因爲如果我擺脫他們的程序工作,除了從按鈕就好了那些顯然不出現;

skin = new Skin(Gdx.files.internal("jsonSkin.json")); 
     TextButton btnStart = new TextButton("Start!!", skin); 
     btnStart.setPosition(50f,400f); 
     btnStart.setSize(260f,60f); 
mainMenu.addActor(btnStart); 
+0

它看起來像您的Proguard配置不是除libgdx類外。由於Skin通過反射來加載類,所以您不能讓Proguard更改這些類的名稱。 – Tenfour04

+0

你確定這存在? '皮膚/ jsonSkin.json' – Madmenyo

+0

Menno Gouw - 我在這裏發佈時可能已經改變了一些東西,但我可以向你保證,我把一個jsonSkin.json放在皮膚/文件夾和資產中。 – user5895975

回答

3

在你的配置將這個:

-keep class com.badlogic.**{ 
    **[] $VALUES; 
    *; 
} 

它會解決這個問題,並反射問題。

0

問題是json序列化程序需要確切的字段名稱來完成其工作。

阿布舍克是正確的,但我只需要忽略僅供scene2d包萎縮,所以我把這個proguard-rules.pro文件

-keep class com.badlogic.gdx.scenes.scene2d.ui.**{ 
    **[] $VALUES; 
    *; 
} 

這將優化所有其它代碼,除了皮膚裝載機及其組件。

另外,如果您正在使用自己的類進行json de /序列化,您還需要添加類似的東西。

-keep class com.your.game.data.**{ 
    **[] $VALUES; 
    *; 
} 

這裏是要找到在Android Studio中的proguard-rules.pro文件初學者 enter image description here

0

proguard的規則

-keep類COM將這個截圖。 badlogic.gdx.graphics.g2d.BitmapFont