4

我正在使用 KeyGenParameterSpec 来定义我的密钥规范。当我运行应用程序时,我在日志中收到以下错误:

原因:java.lang.ClassNotFoundException:在路径上找不到类“android.security.keystore.KeyGenParameterSpec$Builder”:DexPathList[[zip file“/data/app/com.rsa.mobile.transactionsigningsdk-1/base .apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]

下面是我的 MainActivity.java:

 package com.rsa.mobile.transactionsigningsdk;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import com.rsa.mobile.transactionsigningsdk.enrollment.DeviceEnrollmentHelper;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Log.i("Testing message", "App started");
    DeviceEnrollmentHelper deh =new DeviceEnrollmentHelper();
    deh.enroll();
    Log.i("Testing message", "Job Done");


    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

下面是从 MainActivity.java 调用的代码:

 public DeviceEnrollmentResponse enroll() {

    if(isEnrolled()) {
        return new DeviceEnrollmentResponse(null,StatusReasonCode.DEVICE_ALREADY_ENROLLED);
    }
    else{
        try {
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
                    "RSA", "AndroidKeyStore");

            /*KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(android.content.Context this)
                    .setAlias("trsdk")
                    .setSubject(new X500Principal("CN=Sample Name, O=Android Authority"))
                    .setSerialNumber(BigInteger.ONE)
                    .setKeySize(KEY_SIZE)
                    .build();*/
            keyPairGenerator.initialize(
                    new KeyGenParameterSpec.Builder(
                            "trsdk",
                            KeyProperties.PURPOSE_SIGN)
                            .setAlgorithmParameterSpec(new ECGenParameterSpec("secp256r1"))
                            .setDigests(KeyProperties.DIGEST_SHA256,
                                    KeyProperties.DIGEST_SHA384,
                                    KeyProperties.DIGEST_SHA512)
                            .setUserAuthenticationRequired(true)
                            .build());
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            //Get the public key from the KeyPair
            PublicKey pk=keyPair.getPublic();
            //remove
            Log.i("Testing Message","Inside Enroll()");
            Log.i("Testing Message", String.valueOf(pk));

            //To Ask
            if (pk==null){
                return new DeviceEnrollmentResponse(null, StatusReasonCode.UNKNOWN_ERR);
            }
            else{
                return new DeviceEnrollmentResponse(pk, StatusReasonCode.DEVICE_SUCCESSFULLY_ENROLLED);
            }

            } catch (InvalidAlgorithmParameterException e) {
                e.printStackTrace();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (NoSuchProviderException e) {
                e.printStackTrace();
            }
        }
    //To Ask
    return null;
}

下面是我的 AndroidMaifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

下面是应用程序 build.gradle:

应用插件:'com.android.application'

android { compileSdkVersion 23 buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.rsa.mobile.transactionsigningsdk"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
} }

依赖{

compile ('com.thoughtworks.xstream:xstream:1.4.7'){
        exclude group: 'xmlpull'
}
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0' }

以下是错误的堆栈跟踪:

11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:进程:com.rsa.mobile.transactionsigningsdk,PID:27882 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:java.lang.NoClassDefFoundError:解析失败:Landroid/security/keystore/KeyGenParameterSpec$Builder;11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 com.rsa.mobile.transactionsigningsdk.enrollment.DeviceEnrollmentHelper.enroll(DeviceEnrollmentHelper.java:82) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 com.rsa.mobile.transactionsigningsdk.MainActivity.onCreate(MainActivity.java:27) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.app.Activity.performCreate(Activity.java:6088) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 11-24 11:07: 52.485 27882-27882/? E/AndroidRuntime:在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.app.ActivityThread.access$900(ActivityThread.java:154) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1322) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.os.Handler.dispatchMessage(Handler.java:102) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 在 android.os.Looper.loop(Looper.java:135) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 在 android.app.ActivityThread.main(ActivityThread.java: 5290) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 在 java.lang.reflect.Method.invoke(Native Method) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 java.lang.reflect.Method.invoke(Method.java:372) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 11-24 11:07:52.485 27882-27882/?E/AndroidRuntime:在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:原因:java.lang.ClassNotFoundException:在路径上找不到类“android.security.keystore.KeyGenParameterSpec$Builder”:DexPathList [[zip 文件“/data/app/com.rsa.mobile.transactionsigningsdk -1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]] 11-24 11:07: 52.485 27882-27882/? E/Android运行时:
在 dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 java.lang.ClassLoader.loadClass(ClassLoader.java:511) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 java.lang.ClassLoader.loadClass(ClassLoader.java:469) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 com.rsa.mobile.transactionsigningsdk.enrollment.DeviceEnrollmentHelper.enroll(DeviceEnrollmentHelper.java:82) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 com.rsa.mobile.transactionsigningsdk.MainActivity.onCreate(MainActivity.java:27) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.app.Activity.performCreate(Activity.java:6088) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:位于 android.app.Instrumentation。callActivityOnCreate(Instrumentation.java:1106) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.app.ActivityThread.access$900(ActivityThread.java:154) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1322) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 android.os.Handler.dispatchMessage(Handler.java:102) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 在 android.os.Looper.loop(Looper.java:135) 11-24 11:07:52.485 27882-27882/? E/Android运行时:在 android.app.ActivityThread.main(ActivityThread.java:5290) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 在 java.lang.reflect.Method.invoke(Native Method) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 java.lang.reflect.Method.invoke(Method.java:372) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 11-24 11:07:52.485 27882-27882/?E/AndroidRuntime:在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: 抑制: java.lang.ClassNotFoundException: android.security.keystore.KeyGenParameterSpec$Builder 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 java.lang.Class.classForName(Native Method) 11-24 11:07:52。485 27882-27882/? E/AndroidRuntime:在 java.lang.BootClassLoader.findClass(ClassLoader.java:781) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime:在 java.lang.ClassLoader.loadClass(ClassLoader.java:504) 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: ... 16 更多 11-24 11:07:52.485 27882-27882/? E/AndroidRuntime: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; 没有可用的堆栈 11-24 11:07:52.485 32736-32736/? D/AsyncTaskServiceImpl:提交任务:k 11-24 11:07:52.487 27882-27882/? D/AppTracker:应用事件:崩溃 11-24 11:07:52.487 1092-22412/? W/ActivityManager:getRunningAppProcesses:调用者 10156 不持有 REAL_GET_TASKS;限制输出 11-24 11:07:52.489 1092-10061/? W/ActivityManager:getRunningAppProcesses:调用者 10156 不持有 REAL_GET_TASKS;限制输出 11-24 11:07:52.490 32736-27837/? D/k:处理包:com.rsa.mobile.transactionsigningsdk 11-24 11:07:52.490 32736-32736/? D/ChimeraCfgMgr:从 APK com.google.android.gms 11-24 11:07:52.492 1092-4065/ 加载模块 com.google.android.gms.vision D/WifiService:客户端连接丢失原因:4 11-24 11:07:52.503 1092-4736/?W/ActivityManager:强制完成活动 1 com.rsa.mobile.transactionsigningsdk/.MainActivity 11-24 11:07:52.505 13111-13111/? E/NetworkScheduler.SchedulerReceiver:无效参数应用程序 11-24 11:07:52.505 13111-13111/?E/NetworkScheduler.SchedulerReceiver:无效的包名:也许你没有 t 在额外内容中包含 PendingIntent 吗?11-24 11:07:52.520 1092-27935/? D/DropBoxManagerService: 文件 :: /data/system/dropbox/data_app_crash@1448343472518.txt 11-24 11:07:52.535 1092-1169/? W/ActivityManager:关闭应用程序错误对话框:com.rsa.mobile.transactionsigningsdk 11-24 11:07:52.537 27882-27882/? I/Process:发送信号。PID: 27882 SIG: 9 11-24 11:07:52.549 32736-27837/? D/GassUtils:找到包 com.rsa.mobile.transactionsigningsdk:1 的应用信息。哈希:b6b6c7a4a5de3ea7df9c51284188b1040033e02a491ec95fee9371f7817bc00c 11-24 11:07:52.549 32736-27837/? D/k:在 db 中找到包 com.rsa.mobile.transactionsigningsdk 的信息。11-24 11:07:52.562 1092-10061/? I/ActivityManager:启动 proc 27936:com.yatra.base/u0a143 广播 com.yatra.base/com.moe.pushlibrary.AppUpdateReceiver 11-24 11:07:52。562 367-367/? E/lowmemorykiller:写入 /proc/27882/oom_score_adj 时出错;错误号=22 11-24 11:07:52.581 1092-22411/?I/ActivityManager:进程 com.rsa.mobile.transactionsigningsdk (pid 27882) 已于 11-24 11:07:52.582 1092-1163/? V/ActivityManager:线程 16 11-24 11:07:52.587 27936-27936/上的 PID 27882 的 killProcessGroupAsync 花费了 0 毫秒/?W/ResourcesManager:资产路径“/system/framework/com.google.android.maps.jar”不存在或不包含资源。11-24 11:07:52.601 27936-27936/? I/MultiDex:2.1.0 版本的 VM 支持 multidex 11-24 11:07:52.601 27936-27936/? I/MultiDex:安装 11-24 11:07:52.601 27936-27936/? I/MultiDex:VM 有 multidex 支持,MultiDex 支持库被禁用。11-24 11:07:52.601 27936-27936/? I/MultiDex:安装 11-24 11:07:52.601 27936-27936/? I/MultiDex:VM 有 multidex 支持,MultiDex 支持库被禁用。11-24 11:07:52.614 27936-27936/? D/MoEngage_v510:MoEController:Context 为 null 现在无法绑定服务。11-24 11:07:52.616 1092-1181/? W/WindowManager:查找窗口 11-24 11:07:52.616 1092-1181/ 失败?W/WindowManager: java.lang.IllegalArgumentException: 请求的窗口 android.view.ViewRootImpl$W@35e88e7 不存在 11-24 11:07:52.616 1092-1181/?W/WindowManager:在 com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8708) 11-24 11:07:52.616 1092-1181/?W/WindowManager:在 com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8699) 11-24 11:07:52.616 1092-1181/?W/WindowManager: 在 com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java: 2620) 11-24 11:07:52.616 1092-1181/? W/WindowManager:在 com.android.server.wm.Session.remove(Session.java:187) 11-24 11:07:52.616 1092-1181/?W/WindowManager:在 android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3015) 11-24 11:07:52.616 1092-1181/?W/WindowManager:在 android.view.ViewRootImpl.doDie(ViewRootImpl.java:5502) 11-24 11:07:52.616 1092-1181/?W/WindowManager:在 android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3321) 11-24 11:07:52.616 1092-1181/?W/WindowManager:在 android.os.Handler.dispatchMessage(Handler.java:102) 11-24 11:07:52.616 1092-1181/?W/WindowManager:在 android.os.Looper.loop(Looper.java:135) 11-24 11:07:52.616 1092-1181/?W/WindowManager:在 android.os.HandlerThread.run(HandlerThread.java:61) 11-24 11:07:52。616 1092-1181/? W/WindowManager:在 com.android.server.ServiceThread.run(ServiceThread.java:46) 11-24 11:07:52.618 27936-27936/?I/MoEngage_v510:MoEUtils:SDK 已初始化。MoEngage SDK 版本:510 11-24 11:07:52.618 1092-22411/? W/InputMethodManagerService:窗口已经聚焦,忽略焦点增益:com.android.internal.view.IInputMethodClient$Stub$Proxy@34f79c48 attribute=null, token = android.os.BinderProxy@132d42ec

任何人都可以帮忙:我已经尝试清理项目,按照相关问题中的建议重新导入它。提前致谢!

4

1 回答 1

2

这是因为您使用的设备没有使用 API 23(Android 6.0 或更高版本)

于 2015-12-30T11:29:44.663 回答