当尝试使用GeckoView制作浏览器时,出现java.lang.ClassNotFoundException。

问题描述 投票:0回答:1

我对java编程很陌生。在尝试使用本地存储的GECKOVIEW库制作浏览器时,遇到一个错误信息。构建确实完成,但应用程序崩溃。如果能得到帮助,我将非常感激,因为我很困,而且事实证明很难找到关于GeckoView出现的问题的信息。

错误信息。

FATAL EXCEPTION: main Process: com.example.browser, PID: 12465  
 java.lang.NoClassDefFoundError: Failed resolution of: 
Lorg/yaml/snakeyaml    /constructor/Constructor;**strong text**

Caused by: java.lang.ClassNotFoundException: Didn't find class 
"org.yaml.snakeyaml.constructor.Constructor" on path: DexPathList[[zip file 
"/data/app/com.example.browser-REepjBL5JVM2lFFcNMNHJA==
/base.apk"],nativeLibraryDirectories=[/data/app/com.example.browser-
REepjBL5JVM2lFFcNMNHJA==/lib/arm64, /data/app/com.example.browser-
REepjBL5JVM2lFFcNMNHJA==/base.apk!/lib/arm64-v8a, /system/lib64, /product    /lib64]]

(完整的错误信息在底部)

建立Gradle:APP。

   apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
    applicationId "com.example.browser"
    minSdkVersion 29
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation(name:'gclib',ext:'aar')
}

GeckoView库被复制粘贴到项目库文件夹中。

建立Gradle项目。

// Top-level build file where you can add configuration options common to 
all sub-projects/modules.

buildscript {

repositories {
    google()
    jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.6.3'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
    flatDir{
        dirs 'libs'
    }

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

MAIN ACTIVITY:

public class MainActivity extends AppCompatActivity {

private GeckoView geckoview;
private GeckoSession geckoSession;
private GeckoRuntime geckoRuntime;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    geckoview = findViewById(R.id.geckoView);

    geckoSession = new GeckoSession();
    geckoSession.getSettings().setUseTrackingProtection(true);
    geckoSession.getSettings().getUsePrivateMode();
    geckoSession.getSettings().setUserAgentMode(0);
    GeckoRuntimeSettings.Builder builder = new GeckoRuntimeSettings.Builder()
            .aboutConfigEnabled(true)
            .useMultiprocess(false)
            .forceUserScalableEnabled(true)
            .javaScriptEnabled(true);
    geckoRuntime = GeckoRuntime.create(MainActivity.this,builder.build());
    geckoSession.open(geckoRuntime);
    geckoview.setSession(geckoSession);
    geckoSession.loadUri("Https://duckduckgo.com");

}
}

完整的错误信息。

2020-04-25 01:11:44.403 12465-12465/com.example.browser E/AndroidRuntime:         FATAL EXCEPTION: main
Process: com.example.browser, PID: 12465
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/yaml/snakeyaml/constructor/Constructor;

    at org.mozilla.gecko.util.DebugConfig.fromFile(DebugConfig.java:40)
    at org.mozilla.geckoview.GeckoRuntime.init(GeckoRuntime.java:362)
    at org.mozilla.geckoview.GeckoRuntime.create(GeckoRuntime.java:546)
    at com.example.browser.MainActivity.onCreate(MainActivity.java:32)
    at android.app.Activity.performCreate(Activity.java:7955)
    at android.app.Activity.performCreate(Activity.java:7944)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3423)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7814)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)

 Caused by: java.lang.ClassNotFoundException: Didn't find class 
 "org.yaml.snakeyaml.constructor.Constructor" on path: DexPathList[[zip file
"/data/app/com.example.browser-REepjBL5JVM2lFFcNMNHJA==
/base.apk"],nativeLibraryDirectories=[/data/app/com.example.browser-
REepjBL5JVM2lFFcNMNHJA==/lib/arm64, /data/app/com.example.browser-
REepjBL5JVM2lFFcNMNHJA==/base.apk!/lib/arm64-v8a, /system/lib64, /product
/lib64]]

    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at org.mozilla.gecko.util.DebugConfig.fromFile(DebugConfig.java:40) 
    at org.mozilla.geckoview.GeckoRuntime.init(GeckoRuntime.java:362) 
    at org.mozilla.geckoview.GeckoRuntime.create(GeckoRuntime.java:546) 
    at com.example.browser.MainActivity.onCreate(MainActivity.java:32) 
    at android.app.Activity.performCreate(Activity.java:7955) 
    at android.app.Activity.performCreate(Activity.java:7944) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3423) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:237) 
    at android.app.ActivityThread.main(ActivityThread.java:7814) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at     com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047) 
2020-04-25 01:11:44.420 12465-12465/com.example.browser I/Process: Sending     signal. PID: 12465 SIG: 9
compatibility geckoview
1个回答
0
投票

问题解决了。

Bij将geckoview pom文件中提到的依赖关系添加到build gradle app的依赖关系块中,原来的问题得到了解决。

新的问题出现了,当sqlite库无法加载时,显然新版本的android studio默认为extractnativelibs=false。通过在androidmanifest.xml中添加android:extractNativeLibs="true",问题就解决了。

© www.soinside.com 2019 - 2024. All rights reserved.