美文网首页
Android 开发中问题总结

Android 开发中问题总结

作者: 释校尉 | 来源:发表于2019-04-09 20:30 被阅读0次

1.建立Activity出现 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo异常

解决办法:配置错误,安装使用了以前的配置,重新建立一个配置,就可以了

2.getColor()和getDrawable()过时问题

解决办法:getColor()替换成ContextCompat.getColor()

                  getDrawable()替换成ContextCompat.getDrawable()

3.AndroidStudio3.0 Canary 8报错:

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

解决办法:在app的build中

android {

    defaultConfig {

        //添加如下配置就OK了

        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }

    }

}

4.Failed to load memtrack module -2

解决办法:<manifest android:installLocation="preferExternal">

5.Missing contentDescription attribute on image的问题

解决办法:android:contentDescription="@string/app_name“

6.打开Android Studio报错“Error running Please select Android SDK”

解决办法:

(1).首先依次选择主菜单“File”——“Settings”

(2).展开“Appearance & Behavior”——“System Settings”——“Android SDK”,在右边的设置界面编辑SDK的路径

(3).单击“Edit”链接之后打开SDK的设置界面如下图所示,这里SDK的目录保持不动,单击页面下方的“Next”按钮,在下一个页面继续单击“Next”按钮,等待Android Studio下载最新的编译工具,我这边是下载了最新的27.0.2版的build-tools。下载完成后单击页面右下角的“Finish”按钮完成更新操作。

(4).回到Android Studio的主界面,此时会自动同步编译工具并重新编译,等待重编完成,即可正常执行Run app的操作了。

7.No toolchains found in the NDK toolchains folder for ABI with prefix mips64el-linux-android错误

解决办法:新版本的NDK与3.0及以前旧版的Android Gradle plugin插件不兼容,修改build.gradle中的版本,改为3.1以上版本即可

8.Android 解决APP字体随系字体大小改变造成的布局错位问题

解决办法:在工程的Application或BaseActivity中添加下面的代码:(在ApplicAtion 测试成功)

@Overridepublic void onConfigurationChanged(Configuration newConfig) {

    if (newConfig.fontScale != 1)//非默认值

        getResources();   

    super.onConfigurationChanged(newConfig);

}

@Overridepublic Resources getResources() {

    Resources res = super.getResources();

    if (res.getConfiguration().fontScale != 1) {//非默认值

        Configuration newConfig = new Configuration();     

        newConfig.setToDefaults();//设置默认       

        res.updateConfiguration(newConfig, res.getDisplayMetrics());

    }   

    return res;

}

9.解决SplashActivity出现白屏问题

解决办法:

    <!--全屏-->

    <style name="SplashFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="android:windowFullscreen">true</item>

        <!--防止出现启动白屏,以下两句不可少-->

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

        <item name="android:windowBackground">@drawable/splash_icon</item>

    </style>

然后在Activty配置文件中配置 android:theme="@style/SplashFullScreenTheme" 即可。

如果SplashActivity 中必须设置背景颜色,否则可能出现透明背景。

10.ErrorAll flavors must now belong to a named flavor dimension

解决办法:必须要保证所有的flavor 都属于同一个维度

defaultConfig {

    applicationId "com.*********.app"

    minSdkVersion 15

    targetSdkVersion 22

    multiDexEnabled true

    //动态指定版本号版本名

    versionCode project.hasProperty('VERSION_CODE') ? Integer.parseInt(VERSION_CODE) : DEF_VERSION_CODE

    versionName project.hasProperty('VERSION_NAME') ? VERSION_NAME : "${DEF_VERSION_NAME}"

    println("versionCode = " + versionCode + " versionName = " + versionName)

    buildConfigField("String", "API_HOST", "${API_RELEASE_HOST}")

    //必须要保证所有的flavor 都属于同一个维度

    flavorDimensions "default"

}

相关文章

网友评论

      本文标题:Android 开发中问题总结

      本文链接:https://www.haomeiwen.com/subject/fitwiqtx.html