本文介绍了Android找不到类'android.app.job.JobScheduler'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用选项 minifyEnabled true 构建apk文件时,我一直收到此错误。

I'm keep getting this error while build apk file with option minifyEnabled true.

应用程序生成过程

我很累,找不到类库。我对Android应用程序开发不太熟悉,请帮助我

I have tired to find the the class library. I'm not much familiar with Android app development, please help me with this,

错误堆栈跟踪

05-11 11:44:09.307 10196-10196/? E/cutils: to chown(/mnt/shell/emulated/0, 0, 0)
05-11 11:44:09.307 10196-10196/? E/cutils: to chown(/mnt/shell/emulated/obb, 0, 0)
05-11 11:44:09.308 10196-10196/? E/cutils: to chown(/storage/emulated/0/Android, 0, 0)
05-11 11:44:09.308 10196-10196/? E/cutils: to chown(/storage/emulated/0/Android/obb, 0, 0)
05-11 11:44:09.393 10196-10196/? E/dalvikvm: Could not find class 'android.app.job.JobScheduler', referenced from method com.google.android.gms.internal.zzcll.zzbax
05-11 11:44:09.394 10196-10196/? E/dalvikvm: Could not find class 'android.app.job.JobScheduler', referenced from method com.google.android.gms.internal.zzcll.zzs
05-11 11:44:09.405 10196-10211/? E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.internal.zzbhe.zzf
05-11 11:44:09.647 10196-10216/? E/JniHelper: Failed to find static method id of setAnimationInterval
    Failed to find static java method. Class name: org/cocos2dx/lib/Cocos2dxRenderer, method name: setAnimationInterval, signature: (F)V
05-11 11:44:09.840 10196-10216/? E/JniHelper: Failed to find static method id of setAnimationInterval
    Failed to find static java method. Class name: org/cocos2dx/lib/Cocos2dxRenderer, method name: setAnimationInterval, signature: (F)V
05-11 11:44:09.872 10196-10216/? E/AndroidRuntime: FATAL EXCEPTION: GLThread 11342
    java.lang.NoClassDefFoundError: org/cocos2dx/lib/Cocos2dxDownloader
        at org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(Native Method)
        at org.cocos2dx.lib.Cocos2dxRenderer.onSurfaceCreated(Cocos2dxRenderer.java:73)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "org.cocos2dx.lib.Cocos2dxDownloader" on path: DexPathList[[zip file "/data/app/com.company.game-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.company.game-1, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        at org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(Native Method) 
        at org.cocos2dx.lib.Cocos2dxRenderer.onSurfaceCreated(Cocos2dxRenderer.java:73) 
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494) 
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) 

gradle.properties

PROP_COMPILE_SDK_VERSION=14
PROP_MIN_SDK_VERSION=14
PROP_TARGET_SDK_VERSION=22
PROP_APP_PLATFORM=14

# Supported ABIs are [armeabi,arm64-v8a, armeabi-v7a, mips, x86].
PROP_APP_ABI=armeabi-v7a:x86

build.gradle

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'

android {
    compileSdkVersion 14
    signingConfigs {
        release {
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }
    defaultConfig {
        applicationId "com.company.game"
        minSdkVersion PROP_MIN_SDK_VERSION
        targetSdkVersion PROP_TARGET_SDK_VERSION
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            ndkBuild {
                if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
                    // skip the NDK Build step if PROP_NDK_MODE is none
                    targets 'game'
                    arguments 'NDK_TOOLCHAIN_VERSION=4.9'
                    arguments 'APP_PLATFORM=android-' + PROP_APP_PLATFORM

                    def module_paths = [project.file("../../cocos2d").absolutePath,
                                        project.file("../../cocos2d/cocos").absolutePath,
                                        project.file("../../cocos2d/external").absolutePath]
                    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                        // should use '/'
                        module_paths = module_paths.collect { it.replaceAll('\\\\', '/') }
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
                    } else {
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
                    }

                    arguments '-j' + Runtime.runtime.availableProcessors()
                    abiFilters.addAll(PROP_APP_ABI.split(':').collect { it as String })
                }
            }
        }
        signingConfig signingConfigs.release
    }
    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "../../Resources"
    }
    externalNativeBuild {
        ndkBuild {
            if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
                // skip the NDK Build step if PROP_NDK_MODE is none
                path "jni/Android.mk"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled true // Here
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                signingConfig signingConfigs.release
            }
            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=0'
                }
            }
        }
        debug {
            minifyEnabled true // and here
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=1'
                }
            }
        }
    }
    buildToolsVersion '27.0.3'
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':libcocos2dx')
    implementation 'com.google.firebase:firebase-ads:11.8.0'
    implementation 'com.google.android.gms:play-services-base:11.8.0'
}

apply plugin: 'com.google.gms.google-services'

proguard-rules.pro

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in E:\developSoftware\Android\SDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# 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 *;
#}

#-keep class com.google.android.gms.** { *; }
#-dontwarn com.google.android.gms.**

# com.google.android.gms:play-services-base:11.8.0
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

# com.google.firebase:firebase-ads:11.8.0
-keep public class com.google.firebase.* { public *; }
-dontwarn com.google.firebase.**

-keep public class com.google.android.gms.ads.* { public *; }
-dontwarn com.google.android.gms.ads.**

-keep public class com.google.ads.** { public *; }
-dontwarn com.google.ads.**

这是Cocos2d-x v3 c ++游戏。谢谢

This is a Cocos2d-x v3 c++ Game. Thanks

推荐答案

JobScheduler API是从API 5.0引入的。因此,由于遇到错误

JobScheduler API is was introduced from API 5.0. So it won't work on older versions like 4.2.2 as a result you encounter the error

对于低于5.0的版本,请使用 Firebase JobDispatcher 。有关更多详细信息,请参见此。

For versions lower than 5.0, use Firebase JobDispatcher. Refer this documentation for more details.

您还应该将 compileSdkVersion 从14更新为26或27。

You should also update compileSdkVersion to 26 or 27 from 14.

这篇关于Android找不到类'android.app.job.JobScheduler'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:22