Android 錯誤集合


1. Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

解決:

在工程的gradle.properties文件中添加以下命令:

android.enableAapt2=false

 2. java.net.ProtocolException: Unexpected status line: <html>

原因:

在網絡請求的 url 地址上所帶參數 password 通過 Base64.DEFAULT 加密后,帶有 \n 換行符,即參數的問題導致該問題。

 解決:

通過 Base64.NOWRAP 去掉換行后,錯誤解決。

3. java.lang.IllegalStateException:Not allowed to start service Intent : app is in background uid UidRecord

Android 8.0 不再允許后台service直接通過startService方式去啟動,我們需要 context.startService()替換為context.startForegroundService();

Intent i = new Intent(context, MediaPlaybackService.class);
context.startForegroundService(i, CURRENT);

MediaPlaybackService onCreate()方法 設置為前台進程:

public void onCreate() {
       super.onCreate();
      NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // notification id
    final String channelId = MusicBrowserActivity.MUSIC_NOTIFICATION_CHANNEL;
    // create notification channel
    NotificationChannel mChannel = new NotificationChannel(channelId, "MUSIC", NotificationManager.IMPORTANCE_LOW);
    mNotificationManager.createNotificationChannel(mChannel);
    // set channel id
    Notification status = new Notification.Builder(MediaPlaybackService.this).setChannelId(channelId).build();
    // start for foreground process
    startForeground(PLAYBACKSERVICE_STATUS, status);
}

4. Faild to post notification on channel "null"

NotificationChannel 是 android8.0 新增的特性,如果App的 targetSDKVersion >= 26,沒有設置 channel 通知渠道的話,就會導致通知無法展示。

解決: 創建 Channel

String channelID = "1"; 
String channelName = "channel_name"; NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.createNotificationChannel(channel); Notification.Builder builder = new Notification.Builder(context); builder.setContentText(msgDesc);
builder.setContentTitle(msgTitle);
//創建通知時指定channelID builder.setChannelId(channelID); Notification notification = builder.build();

上面代碼是針對android8.0,我們還要兼容低版本系統以及channel屬性設置。

5. found an invalid color.         java.util.concurrentException:com.android.builder.interal.aapt.v2.Aapt2Exception: AAPT2 error

出現這個問題的原因是項目中引入了一個 .9 圖片引起的,需要更改一下.9圖片的四邊的黑線(拉長或者縮短都可以)。

6. No signature of method: static org.gradle.api.java.archives.Manifest.srcFile() is applicable for argument types: (java.lang.String) values ...

 7. Kotlin compiler: 

  Unresolved reference: BaseApplication     

   'onCreate' overrides nothing

場景: 在 common 組件里放置 BaseApplication 或者 BaseActivity ,在其他 module 中繼承出現這個問題。原因是 common 組件未配置 kotlin

解決: 在 common 的 build.gradle 最上方添加:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

 8. javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT

  導致這個問題的原因就是 密鑰不對 ,要嚴格按照密鑰的生成規則

9. Error: Program type already present:  ****** .BuildConfig

    Android studio Throwing the wrong way is because 2 module have the same package name in AndroidManifest.xml, and can modify different names. 這個問題是出現在 Android 4.x ,在Android 5.x以上就沒有問題了。根本原因未探索

解決: 將相同包名中的其中一個改成其他報名

10. java.lang.IllegalArgumentException: Unknown pattern character 'X'

  "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" 使用該格式轉化時間格式,出現問題 。測試:Android6.0 以及 Android4.4上均出現問題。  原因:X is available only from Nougat+.

苟且解決方案: 將 "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"  改為 "yyyy-MM-dd'T'HH:mm:ss.SSS"

11. io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with.

解決:

 

//RxJava2 取消訂閱后,拋出的異常無法捕獲,導致程序崩潰
        RxJavaPlugins.setErrorHandler {
            LogUtil.e(it.message ?: "RxJavaError")
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM