我使用Intellij。一切都工作正常,和APK部署在我的Android,但它只是保持黑屏,回到家里说,“'游戏'停止:
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);
4条答案
按热度按时间lvmkulzt1#
把这个放在你的配置里:
它将解决这个问题,以及反射的问题。
编辑:
以上是禁用特定软件包上所有
ProGuard’s
优点的顶级规则。不缩水,不混淆视听;不是为了班级,不是为了成员。Proguard
混淆了我们在皮肤文件中使用的类,Skin
通过反射加载类,所以我们必须不允许Proguard
更改这些类的名称。1.包中的双星号表示该顶级包下的每个包下的每个类;
1.大括号中的星号适用于该类中的每个成员(变量、方法和常量)。
ru9i0ody2#
问题是json序列化器需要确切的字段名称来完成其工作。
Abhishek是正确的,但我只需要忽略scene 2d包的收缩,所以我把它放在proguard-rules.pro文件中
它将优化除皮肤加载器及其组件之外的所有其他代码。
如果你用自己的类做json de/序列化,你也需要放一些类似的东西。
下面是一个屏幕截图,用于在Android Studio for beginners上查找proguard-rules.pro文件x1c 0d1x
g9icjywg3#
把这个写进你的proguard规则里
vlf7wbxs4#
在我的
build.gradle
案例中,我为发布版本配置了以下配置:但是我的
proguard-rules.pro
文件丢失了-现在默认为proguard-project.txt
。所以我把config改成了这个:然后应用适当的proguard规则在前面的答案。