4

GeckoEngineView 无法膨胀,尽管使用了最新的依赖项。

该代码来自GeckoView上的官方文档。所有最新的依赖项和 repos 都已在项目中成功解决。

错误:

Error inflating class mozilla.components.browser.engine.gecko.GeckoEngineView

搜索错误日志后:

 Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class mozilla.components.browser.engine.gecko.GeckoEngineView
 Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class mozilla.components.browser.engine.gecko.GeckoEngineView
 Caused by: java.lang.ClassNotFoundException: Didn't find class "mozilla.components.browser.engine.gecko.GeckoEngineView" on path: DexPathList[[zip file "/data/app/com.geckoengine.example-IQhwqfpsfzKO11EI9ak6kQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.geckoengine.example-IQhwqfpsfzKO11EI9ak6kQ==/lib/arm64, /data/app/com.geckoengine.example-IQhwqfpsfzKO11EI9ak6kQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]

更新的 XML 文件,来源:@ArturoMejia
activity_main.xml

<org.mozilla.geckoview.GeckoView
    android:id="@+id/geckoview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

MainActivity.java

public class MainActivity extends AppCompatActivity {

    GeckoView view;
    GeckoSession session;
    GeckoRuntime runtime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        view = findViewById(R.id.geckoview);
        session = new GeckoSession();
        runtime = GeckoRuntime.create(this);
        session.open(runtime);
        view.setSession(session);


        //TODO: add any url
        //TODO: Use intent.putExtraString() to send a url from the main activity to this activity
        session.loadUri("http://theyouthbuzz.com/");
    }
}

该文档暗示代码应该毫无问题地加载 web 视图。同样无法验证。

笔记:

Android Studio 版本:3.5 RC 3 [开发频道]

4

2 回答 2

4

@SowingFiber 我认为您在上面示例的 XML 代码上有一个小错误,可能在上一版中。我认为您应该更新它,因为就像现在一样,它不会编译。

问题是您有两种不同类型的引用,一种在 XML 中,另一种在代码中。要匹配代码中的引用,您必须org.mozilla.geckoview.GeckoView在 XML 中使用。

<org.mozilla.geckoview.GeckoView
    android:id="@+id/geckoview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

此外,如果您只想geckoview使用.geckoview

implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}:${geckoviewVersion}"   
于 2019-08-22T13:48:10.950 回答
2

如组件文档中所述,要使用它,您必须在您的build.gradle

implementation "org.mozilla.components:browser-engine-gecko:{latest-version}"

目前最新版本为 9.0.0

implementation "org.mozilla.components:browser-engine-gecko:9.0.0"
于 2019-08-22T08:07:55.737 回答