Android 開發(fā)中的bug和知識點總結(jié)(持續(xù)更新中)

1.多語言設(shè)置:
https://blog.csdn.net/qq_21983189/article/details/73735278
https://blog.csdn.net/gh8609123/article/details/62440795

2.導(dǎo)入舊項目慢:

改gradle的版本。
改local.properties配置。
改classpath

3.經(jīng)典bug

Error:Execution failed for task ':app:transformClassesWithDesugarForDebug'.

com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.google.devtools.build.android.desugar.Desugar with arguments {@C:\projects\sxyz\app\build\intermediates\tmp\desugar_args4363382331831664290}+

怎么build都不行,更換jdk就好了。

bug.png

4.Could not reserve enough space for 1572864KB object heap。
當(dāng)前項目gradle.properties中:org.gradle.jvmargs=-Xmx1536m 改成

org.gradle.jvmargs=-Xmx1536
MaxHeapSize=512m

或者直接改成:

 org.gradle.jvmargs=-Xmx512m

在as啟動頁面:
2.png

5.讓輸入法自動彈出:
android:windowSoftInputMode="stateVisible|adjustPan"
隱藏:android:windowSoftInputMode="stateVisible|stateHidden"

6."stateHidden|adjustResize"和"stateHidden|adjustPan"區(qū)別:
"adjustResize"在使用時,布局會被軟鍵盤頂上去,體驗非常不好
"adjustPan"在使用時獲取焦點的控件下邊的View將會被軟鍵盤覆蓋。

stateHidden與stateAlwaysHidden:
stateHidden:用戶選擇activity時,軟鍵盤總是被隱藏。
stateAlwaysHidden:當(dāng)該Activity主窗口獲取焦點時,軟鍵盤也總是隱藏的。

stateVisible與stateAlwaysVisible:
stateVisible:軟鍵盤通常是可見的。
stateAlwaysVisible:用戶選擇activity時,軟鍵盤總是顯示的狀態(tài)。

6.Google官方demo網(wǎng)站:https://github.com/googlesamples

  1. Error:(16, 49) String types not allowed (at 'layout_constraintBottom_toBottomOf' with value 'parent')

錯誤布局:

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

修改方法:在根目錄添加id。

android:id="@+id/lay_root"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"
tools:context="com.cheerchip.testskining.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="@+id/lay_root"
    app:layout_constraintLeft_toLeftOf="@+id/lay_root"
    app:layout_constraintRight_toRightOf="@+id/lay_root"
    app:layout_constraintTop_toTopOf="@+id/lay_root" />

8

 .java.lang.ClassCastException: android.graphics.drawable.VectorDrawable cannot be cast to    android.graphics.drawable.BitmapDrawable

以為是不能強(qiáng)轉(zhuǎn),結(jié)果魅族pro6s報錯,其余幾臺測試機(jī)ok。重啟了幾遍AS,結(jié)果就好了。

  1.  Error:android-apt plugin is incompatible with the Android Gradle plugin.  Please use 'annotationProcessor' configuration instead.
    

刪除:

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
apply plugin: 'android-apt'
 javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }  

10.Disconnected from the target VM, address: 'localhost:8601', transport: 'socket'
項目正常能跑,調(diào)試就奔潰。突然之間就出現(xiàn)了這個問題。
第一反應(yīng),去看有沒有端口沖突。沒有。第二份反應(yīng),回憶有沒有做別的操作,沒有。
于是重啟AS,重啟電腦,依舊不行。開始百度,谷歌,各種方法,試了十來種,一個都不行。
機(jī)智的同事,把我的網(wǎng)線拔了,重啟AS就好了。

  1. This Activity already has an action bar supplied by the window decor. Do not request 
    Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
    解決辦法:
    <item name="windowNoTitle">true</item>
    
  2. android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.
    Didn't find class "android.support.v7." on path: DexPathList[[zip file "/data/app/com.szmaiji.sxyz-1/base.apk", zip file "/data/app/com.szmaiji.sxyz-1

布局錯了:<android.support.

13.No cached version of com.android.support:multidex:1.0.2 available for offline

去掉File-Setting-Gradle-Offline work

14.Unknown failure (at android.os.Binder.execTransact(Binder.java:574))
Error while Installing APKs

File ---> Settings ---> Build,Execution,Deployment ---> Instant Run
把Enable Instant Run to選項去掉再重新運(yùn)行一遍就通過了

15.微信回調(diào)失敗。
微信沒有回調(diào)一般就兩點,要么是回調(diào)類配置位置不對,要么就是簽名包名不一致,所以要先檢查回調(diào)信息的,如果是代碼不對會進(jìn)失敗的回調(diào)有錯誤信息的,依次檢查看看。

  1.  Android dependency 'com.android.support:appcompat-v7' has different version for the compile (25.3.1) and runtime (27.0.2) classpath. You should manually set the same version via DependencyResolution
    

17.Android Studio同步svn.

https://www.cnblogs.com/details-666/p/SVN.html

18.Error:null value in entry: aaptFriendlyManifestOutputDirectory=null
刪除.gradle,重新build就好。

19.Android Studio 打開是歡迎頁面:框住的地方取消選中

wel.png

20.Only fullscreen opaque activities can request orientation
修改主題:

     <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowDisablePreview">true</item>

去掉: AndroidManifest.xml中 android:screenOrientation="portrait"

一般問題就是:android:windowIsTranslucent = true 或者android:screenOrientation="portrait" 引起的。

  1. You need to use a Theme.AppCompat theme (or descendant) with this activity.
    自定義的style: <style name="MyDialogStyle1" parent="@style/Theme.AppCompat.Light.NoActionBar">
    或者在 AndroidManifest.xml的相對應(yīng)的Activity那里, android:theme="@style/Theme.AppCompat.Light.NoActionBar"
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容