未知来源的Proguard和Libgdx NullPointerException

时间:2016-04-20 21:03:11

标签: java android libgdx proguard

您好我在我的libgdx项目中尝试使用proguard,但我有一个我无法解决的错误。

这些是我的文件:

build.gradle:

android {
                buildToolsVersion "23.0.3"
                compileSdkVersion 23
                sourceSets {
                    main {
                        manifest.srcFile 'AndroidManifest.xml'
                        java.srcDirs = ['src']
                        aidl.srcDirs = ['src']
                        renderscript.srcDirs = ['src']
                        res.srcDirs = ['res']
                        assets.srcDirs = ['assets']
                        jniLibs.srcDirs = ['libs']
                    }

                    instrumentTest.setRoot('tests')
                }
                defaultConfig {
                    applicationId "com.vabrang.zeros"
                    minSdkVersion 8
                    targetSdkVersion 23
                }

                buildTypes {
                    debug {
                        minifyEnabled true
                        proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
                        proguardFile 'proguard-project.txt'
                    }
                }
            }


            // called every time gradle gets executed, takes the native dependencies of
            // the natives configuration, and extracts them to the proper libs/ folders
            // so they get packed with the APK.
            task copyAndroidNatives() { 
                file("libs/armeabi/").mkdirs();
                file("libs/armeabi-v7a/").mkdirs();
                file("libs/arm64-v8a/").mkdirs();
                file("libs/x86_64/").mkdirs();
                file("libs/x86/").mkdirs();

                configurations.natives.files.each { jar ->
                    def outputDir = null
                    if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
                    if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")        
                    if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
                    if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
                    if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
                    if(outputDir != null) {
                        copy {
                            from zipTree(jar)
                            into outputDir
                            include "*.so"
                        }
                    }
                }
            }

            task run(type: Exec) {
                def path
                def localProperties = project.file("../local.properties")
                if (localProperties.exists()) {
                    Properties properties = new Properties()
                    localProperties.withInputStream { instr ->
                        properties.load(instr)
                    }
                    def sdkDir = properties.getProperty('sdk.dir')
                    if (sdkDir) {
                        path = sdkDir
                    } else {
                        path = "$System.env.ANDROID_HOME"
                    }
                } else {
                    path = "$System.env.ANDROID_HOME"
                }

                def adb = path + "/platform-tools/adb"
                commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.vabrang.zeros/com.vabrang.zeros.AndroidLauncher'
            }

            // sets up the Android Eclipse project, using the old Ant based build.
            eclipse {
                // need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
                // ignores any nodes added in classpath.file.withXml
                sourceSets {
                    main {
                        java.srcDirs "src", 'gen'
                    }
                }

                jdt {
                    sourceCompatibility = 1.6
                    targetCompatibility = 1.6
                }

                classpath {
                    plusConfigurations += [ project.configurations.compile ]        
                    containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'       
                }

                project {
                    name = appName + "-android"
                    natures 'com.android.ide.eclipse.adt.AndroidNature'
                    buildCommands.clear();
                    buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
                    buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
                    buildCommand "org.eclipse.jdt.core.javabuilder"
                    buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
                }
            }

            // sets up the Android Idea project, using the old Ant based build.
            idea {
                module {
                    sourceDirs += file("src");
                    scopes = [ COMPILE: [plus:[project.configurations.compile]]]        

                    iml {
                        withXml {
                            def node = it.asNode()
                            def builder = NodeBuilder.newInstance();
                            builder.current = node;
                            builder.component(name: "FacetManager") {
                                facet(type: "android", name: "Android") {
                                    configuration {
                                        option(name: "UPDATE_PROPERTY_FILES", value:"true")
                                    }
                                }
                            }
                        }
                    }
                }
            }

proguard-project.txt:

                # To enable ProGuard in your project, edit project.properties
            # to define the proguard.config property as described in that file.
            #
            # Add project specific ProGuard rules here.
            # By default, the flags in this file are appended to flags specified
            # in ${sdk.dir}/tools/proguard/proguard-android.txt
            # You can edit the include path and order by changing the ProGuard
            # include property in project.properties.
            #
            # For more details, see
            #   http://developer.android.com/guide/developing/tools/proguard.html

            # Add any project specific keep options here:

            # If your project uses WebView with JS, uncomment the following
            # and specify the fully qualified class name to the JavaScript interface
            # class:
            #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
            #   public *;
            #}

            -verbose

            -dontwarn android.support.**
            -dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
            -dontwarn com.badlogic.gdx.utils.GdxBuild
            -dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild
            -dontwarn com.badlogic.gdx.jnigen.BuildTarget*
            -dontwarn com.badlogic.gdx.graphics.g2d.freetype.FreetypeBuild

            -keep class com.badlogic.gdx.controllers.android.AndroidControllers

            -keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
               <init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
            }

            -keepclassmembers class com.badlogic.gdx.physics.box2d.World {
               boolean contactFilter(long, long);
               void    beginContact(long);
               void    endContact(long);
               void    preSolve(long, long);
               void    postSolve(long, long);
               boolean reportFixture(long);
               float   reportRayFixture(long, float, float, float, float, float);
            }

LogCat:

04-20 17:49:26.922 23638-23638/com.vabrang.zeros I/art: Late-enabling -Xcheck:jni
      04-20 17:49:26.978 23638-23650/com.vabrang.zeros I/art: Debugger is no longer active
      04-20 17:49:27.027 23638-23638/com.vabrang.zeros I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016_msm8226_LA.BF.1.1.1_RB1__release_AU ()
                                                                     OpenGL ES Shader Compiler Version: E031.25.03.00
                                                                     Build Date: 02/11/15 Wed
                                                                     Local Branch: 
                                                                     Remote Branch: quic/LA.BF.1.1.1_rb1.10
                                                                     Local Patches: NONE
                                                                     Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016 + 62ca4eb + acd831d + 9f8b442 + e027a02 + cba30ba + 53c303a + a649d79 + 23e16f8 + 5e97da7 + cbd2a44 + 33d072a + 7aacf06 + 72b33e7 + 28f6f60 + b4c13d8 +  NOTHING
      04-20 17:49:27.118 23638-23638/com.vabrang.zeros I/AndroidInput: sensor listener setup
      04-20 17:49:27.126 23638-23679/com.vabrang.zeros D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
      04-20 17:49:27.139 23638-23638/com.vabrang.zeros D/Atlas: Validating map...
      04-20 17:49:27.173 23638-23679/com.vabrang.zeros I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016_msm8226_LA.BF.1.1.1_RB1__release_AU ()
                                                                     OpenGL ES Shader Compiler Version: E031.25.03.00
                                                                     Build Date: 02/11/15 Wed
                                                                     Local Branch: 
                                                                     Remote Branch: quic/LA.BF.1.1.1_rb1.10
                                                                     Local Patches: NONE
                                                                     Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016 + 62ca4eb + acd831d + 9f8b442 + e027a02 + cba30ba + 53c303a + a649d79 + 23e16f8 + 5e97da7 + cbd2a44 + 33d072a + 7aacf06 + 72b33e7 + 28f6f60 + b4c13d8 +  NOTHING
      04-20 17:49:27.173 23638-23679/com.vabrang.zeros I/OpenGLRenderer: Initialized EGL, version 1.4
      04-20 17:49:27.217 23638-23679/com.vabrang.zeros D/OpenGLRenderer: Enabling debug mode 0
      04-20 17:49:27.241 23638-23666/com.vabrang.zeros W/GL2JNIView: creating OpenGL ES 2.0 context
      04-20 17:49:27.246 23638-23666/com.vabrang.zeros W/GL2JNIView: Returning a GLES 2 context
      04-20 17:49:27.253 23638-23666/com.vabrang.zeros I/GL2: all initialized 2
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: OGL renderer: Adreno (TM) 305
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: OGL vendor: Qualcomm
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: OGL version: OpenGL ES 3.0 V@84.0 AU@05.00.02.042.016 (CL@)
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: OGL extensions: GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_AMD_program_binary_Z400 GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_robustness GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_NV_fence GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_depth24 GL_OES_EGL_image GL_OES_EGL_sync GL_OES_EGL_image_external GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_depth_texture_cube_map GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_3D GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_vertex_type_10_10_10_2 GL_OES_vertex_array_object GL_QCOM_alpha_test GL_QCOM_binning_control GL_QCOM_driver_control GL_QCOM_perfmon_global_mode GL_QCOM_extended_get GL_QCOM_extended_get2 GL_QCOM_tiled_rendering GL_QCOM_writeonly_rendering GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_texture_filter_anisotropic GL_EXT_multisampled_render_to_texture GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_disjoint_timer_query 
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:632>: EGL_BAD_ATTRIBUTE
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:632>: EGL_BAD_ATTRIBUTE
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: framebuffer: (5, 6, 5, 0)
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: depthbuffer: (16)
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: stencilbuffer: (0)
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: samples: (0)
      04-20 17:49:27.254 23638-23666/com.vabrang.zeros I/AndroidGraphics: coverage sampling: (false)
      04-20 17:49:27.260 23638-23666/com.vabrang.zeros I/AndroidGraphics: Managed meshes/app: { }
      04-20 17:49:27.260 23638-23666/com.vabrang.zeros I/AndroidGraphics: Managed textures/app: { }
      04-20 17:49:27.264 23638-23666/com.vabrang.zeros I/AndroidGraphics: Managed cubemap/app: { }
      04-20 17:49:27.271 23638-23666/com.vabrang.zeros I/AndroidGraphics: Managed shaders/app: { }
      04-20 17:49:27.271 23638-23666/com.vabrang.zeros I/AndroidGraphics: Managed buffers/app: { }
      04-20 17:49:27.394 23638-23666/com.vabrang.zeros E/AndroidRuntime: FATAL EXCEPTION: GLThread 18522
                                                                         Process: com.vabrang.zeros, PID: 23638
                                                                         java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
                                                                             at com.vabrang.zeros.i.a(Unknown Source)
                                                                             at com.badlogic.gdx.backends.android.j.onSurfaceChanged(Unknown Source)
                                                                             at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511)
                                                                             at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
      04-20 17:49:27.417 23638-23638/com.vabrang.zeros I/AndroidInput: sensor listener tear down
      04-20 17:49:27.417 23638-23638/com.vabrang.zeros I/AndroidGraphics: Managed meshes/app: { }
      04-20 17:49:27.417 23638-23638/com.vabrang.zeros I/AndroidGraphics: Managed textures/app: { }
      04-20 17:49:27.417 23638-23638/com.vabrang.zeros I/AndroidGraphics: Managed cubemap/app: { }
      04-20 17:49:27.417 23638-23638/com.vabrang.zeros I/AndroidGraphics: Managed shaders/app: { }
      04-20 17:49:27.417 23638-23638/com.vabrang.zeros I/AndroidGraphics: Managed buffers/app: { }
      04-20 17:49:29.192 23638-23666/com.vabrang.zeros I/Process: Sending signal. PID: 23638 SIG: 9

1 个答案:

答案 0 :(得分:1)

要查找错误,我可以获得反混淆的堆栈跟踪。 Android SDK中有retrace.sh(或类似的Windows版本)脚本,可以对堆栈跟踪进行反混淆处理。要运行它,您需要在构建期间由ProGuard生成的stacktrace和mapping.txt文件。

但是堆栈跟踪可能不明确 - 它可以为每个堆栈跟踪元素显示多个方法。 要解决此问题并摆脱“未知来源”,请将此规则添加到ProGuard配置中:

-keepattributes SourceFile,LineNumberTable

这样,即使在模糊堆栈跟踪中,您也会看到源文件名和行号。您的反混淆堆栈跟踪也将是明确的。

修改

List of available attributes及其描述。