如何为 android 修复 "Error inflating class GeckoEngineView"
How to fix "Error inflating class GeckoEngineView" for android
尽管使用了最新的依赖项,但 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/");
}
}
文档暗示代码应该可以毫无问题地加载 webview。同样是不可验证的。
备注:
Android 工作室版本:3.5 RC 3 [开发频道]
如组件 doc 中所述,要使用它,您必须在 build.gradle
中添加此依赖项
implementation "org.mozilla.components:browser-engine-gecko:{latest-version}"
目前 latest version 是 9.0.0
implementation "org.mozilla.components:browser-engine-gecko:9.0.0"
@SowingFiber 我认为您在上一版中的 XML 代码中有一个小错误,可能出现在上一版中。我认为你应该更新它,因为它现在无法编译。
问题是您有两种不同类型的引用,一种在 XML 中,另一种在代码中。要匹配代码中的引用,您必须在 XML.
中使用 org.mozilla.geckoview.GeckoView
<org.mozilla.geckoview.GeckoView
android:id="@+id/geckoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
此外,您可以直接包含 geckoview
,而不使用 Mozilla Android Components,以防您只想使用 geckoview
.
implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}:${geckoviewVersion}"
尽管使用了最新的依赖项,但 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/");
}
}
文档暗示代码应该可以毫无问题地加载 webview。同样是不可验证的。
备注:
Android 工作室版本:3.5 RC 3 [开发频道]
如组件 doc 中所述,要使用它,您必须在 build.gradle
implementation "org.mozilla.components:browser-engine-gecko:{latest-version}"
目前 latest version 是 9.0.0
implementation "org.mozilla.components:browser-engine-gecko:9.0.0"
@SowingFiber 我认为您在上一版中的 XML 代码中有一个小错误,可能出现在上一版中。我认为你应该更新它,因为它现在无法编译。
问题是您有两种不同类型的引用,一种在 XML 中,另一种在代码中。要匹配代码中的引用,您必须在 XML.
中使用org.mozilla.geckoview.GeckoView
<org.mozilla.geckoview.GeckoView
android:id="@+id/geckoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
此外,您可以直接包含 geckoview
,而不使用 Mozilla Android Components,以防您只想使用 geckoview
.
implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}:${geckoviewVersion}"