在build.grandle应用程序的依赖项下添加implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.2'
后,出现编译错误。当项目正在同步时,它可以正常工作,但是当我尝试编译应用程序时,它会失败。
这是我遇到的错误:
AndroidStudioProjects/Pari365/app/src/main/java/com/maunexus/MainActivity.java:
uses or overrides a deprecated API.
Recompile with -Xlint:deprecation for details.
这是MainActivity.java文件:
package com.maunexus;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private WebView webView;
Activity activity;
private ProgressDialog progDailog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
activity = this;
progDailog = ProgressDialog.show(activity, "Loading", "Please wait...", true);
progDailog.setCancelable(false);
webView = (WebView) findViewById(R.id.webviewid);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setSupportZoom(false);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
progDailog.show();
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, final String url) {
progDailog.dismiss();
}
});
webView.loadUrl("https://pari365.mg");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.super_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_back:
onBackPressed();
break;
case R.id.menu_forward:
onForwardPressed();
break;
case R.id.menu_refresh:
webView.reload();
Toast.makeText(this, "Reloading... Please Wait!", Toast.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}
private void onForwardPressed() {
if (webView.canGoForward()) {
webView.goForward();
} else {
Toast.makeText(this, "Already there! ;)", Toast.LENGTH_SHORT).show();
}
}
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
}
}
}
这是AndroidManifest.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maunexus">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
请帮助我修复错误。谢谢;)
更新:我用ProgressBar替换了ProgressDialog,但是错误仍然存在。
com/maunexus/MainActivity.java
uses or overrides a deprecated API.
com.android.tools.r8.CompilationFailedException: Compilation failed to complete
com.android.tools.r8.utils.AbortException: Error: null, Cannot fit requested classes in a single dex file (# methods: 100707 > 65536)
null
Cannot fit requested classes in a single dex file (# methods: 100707 > 65536)
答案 0 :(得分:1)
这是一个警告,文档中已弃用的类为ProgressDialog
:
该类已在API级别26中弃用。
ProgressDialog
是一个模式对话框,可防止用户与该应用进行交互。代替使用此类,您应该使用进度指示器,例如ProgressBar
,该指示器可以嵌入应用程序的UI中。另外,您可以使用通知来通知用户任务的进度。
https://developer.android.com/reference/android/app/ProgressDialog
您可以使用ProgressBar
代替ProgressDialog
。