asc*_*sco 24 android gradle android-studio
在Android Studio/Gradle Android项目中,我有两个构建变体,Debug和Release(标准项目设置).
你可以在这张图片中看到我的文件夹结构:

我有一个WebView,它应该显示/ res/raw-folder中的imprint.html.WebView说,这适用于发布版本,但不适用于调试版本
Couldn't load website under 'file///android_res/raw/imprint.hml
net::EE_FILE_NOT_FOUND
Run Code Online (Sandbox Code Playgroud)
这让我很困惑.
我究竟做错了什么?
DDs*_*six 13
尝试删除后缀到调试模式.
此外,请确保您有proguard规则
-keepclassmembers class **.R$* {public static <fields>;}
-keep class **.R$*
Run Code Online (Sandbox Code Playgroud)
编辑:找出问题(调试应用程序包后缀".debug")后,尝试以这种方式加载文件:
String path = "android.resource://" + getPackageName() + "/" + R.raw.my_web_file;
Uri myFileUri = Uri.parse(path);
File file = new File(myFileUri.toString());
webview.loadUrl(file.getAbsolutePath());
Run Code Online (Sandbox Code Playgroud)
第二次编辑:如果仍然不起作用(虽然对我来说有效),试试这个:使用输入流将文件加载到webview.
String prompt = "";
try {
InputStream inputStream = getResources().openRawResource(R.raw.my_web_file);
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
prompt = new String(buffer);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
webview.loadData(prompt,"text/html","utf-8");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3214 次 |
| 最近记录: |