Android FAQ

Original: http://www.huwei.tech/2016/05/28/Android%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E9%9B%86% E9% 94% A6 /

Foreword: In development, everyone will encounter more or less various problems. Some problems can be located according to the code debugging, and most of the problems are empirical problems, it is easy to encounter Solve it, but it often takes a lot of time to locate the problem when it is first encountered. In view of this situation, the following will sort out the classic problems encountered since development, I hope to help friends in need!

Note: This article will be updated with the latest questions in the future!

Last Updated: October 10, 2016 10:42 AM

Code class

1. "Stub!" Error occurs when calling Android library in Java project

Description: The console displays an error: Exception in thread "main" java.lang.RuntimeException: Stub!
Cause: When trying to use the org.json.JSONObject class in the Android library in a Java project, a "Stub!" Error appears during execution. The main function of java cannot be executed in the Android project. The Android project and the Java project have certain differences. You cannot mix their libraries and function entry methods.
Solution: Port the executed code to the Android project and execute it correctly!

2. While using shape, the color attribute of shape can be modified through code

Description: Sometimes this kind of demand is encountered: the background identification in different states is different, and the background has a specific shape style.
Reason: The general shape file is to fix the color in xml, so the color value in the shape file needs to be modified in the code.
Solution: Get the background of the control directly through the control, and change the color in the shape file by changing the background color. The code is as follows:

1
2
GradientDrawable gradientDrawable = (GradientDrawable)view.getBackground();
gradientDrawable.setColor(color);

 

3、Failure [INSTALL_FAILED_OLDER_SDK]

Description: When compiling, report Failure [INSTALL_FAILED_OLDER_SDK] error.
Reason: Generally, the system automatically sets the compileSdkVersion for you, and the version is too high.
Solution: Modify compileSdkVersion xxx under build.gradle to compileSdkVersion 19 (or your existing SDK can be used).

4. Abnormal use of Popupwindow: disable to add window–token null is not valid

Description:  Popupwindow must rely on a view to pop up the window, void android.widget.PopupWindow.showAtLocation(View parent, int gravity, int x, int y)
call this method to display Popupwindow, but sometimes you will encounter such an exception: disable to add window – token null is not valid; is your activity running?
Cause: this The reason is generally that showAtLocation is called in the Activity's onCreate () function. Since your popupwindow is attached to an activity, and the onCreate () of the activity has not been executed, it will definitely cause problems if you need to pop up the window.
Solution: Pop-up window in Handler, OK through delay call in onCreate, the specific code is as follows:

1
2
3
4
5
6
7
8
9
10
11
private Handler popupHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
popupWindow.showAtLocation(findViewById(R.id.rlShowImage), Gravity.CENTER|Gravity.CENTER, 0, 0);
popupWindow.update();
break;
}
}
};

 

1
popupHandler.sendEmptyMessageDelayed (0, 1000);

5. When drawing a dotted line with shape, a solid line is displayed on models above 4.0

Description: When drawing a dotted line with shape, it can be displayed normally in Graphical Layout, but the model on Android 4.0 is displayed as a solid line.
Reason:  The hardware acceleration of Activity is turned on by default in 4.0 and above, so we can turn it off in Manifest.xml.
Solution: Add the following attribute to the activity that needs to be displayed: android: hardwareAccelerated = "false", you can also turn off hardware acceleration from the View level view.setLayerType (View.LAYER_TYPE_SOFTWARE, null).

6、Application does not specify an API level requirement

Description: Compile time warning: Application does not specify an API level requirement!
Reason: The API version number is not added in the AndroidManifest.xml or build.gradle file, which does not affect the operation.
Solution: Add the version numbers of minSdkVersion and targetSdkVersion in the corresponding places.

7、Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE

Description: Runtime error: Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE.
Reason: Generally, the default application installation is the mobile phone storage space, and the device does not have enough storage space to install the application.
Solution: Most mobile phones have an SD card. You can set the attribute android: installLocation = ”auto” in the AndroidManifest.xml file.

8. Android image loading Bitmap OOM error solution

Description: When  loading resource images in Android, OOM errors are prone to occur because the Android system has a limit on memory. If this limit is exceeded, OOM will appear. To avoid this problem, you need to consider how to save memory when loading resources. Release resources as soon as possible.
Reason: The  Android system version is different from the image loading and recycling:
1. In Android 2.3 and later, the concurrent recycling mechanism is used to avoid the stuck phenomenon when reclaiming memory;
2. In Android 2.3.3 (API Level 10) and Previously, Bitmap ’s backing pixel data was stored in native memory, which was separate from Bitmap itself. Bitmap itself was stored in the dalvik heap, which caused its pixel data to be judged whether it still needs to be used and not released in time, easily causing OOM errors. (API 11) Beginning, pixel data is stored in the Dalvik heap together with Bitmap.
Solution: When loading image resources, you can use the following methods to avoid OOM problems:
1. Before Android 2.3.3 and before, it is recommended to use the Bitmap.recycle () method to release resources in time;
2. Starting with Android 3.0, you can Set the BitmapFactory.options.inBitmap value (from the cache) to achieve the purpose of reusing Bitmap. If set, the inPreferredConfig attribute value will be overwritten by the reused Bitmap attribute value;
3. Reduce the memory consumption by setting Options.inPreferredConfig value
The default is ARGB_8888: 4 bytes per pixel. A total of 32 bits.
Alpha_8: Only save transparency, total 8 bits, 1 byte.
ARGB_4444: 16 bits in total, 2 bytes.
RGB_565: 16 bits in total, 2 bytes.
If you don't need transparency, you can change the default value ARGB_8888 to RGB_565, saving half the memory.
4. By setting Options.inSampleSize to compress large pictures, you can first set Options.inJustDecodeBounds to obtain the peripheral data of Bitmap, such as width and height. Then calculate the compression ratio and perform compression;
5. Set Options.inPurgeable and inInputShareable: to allow the system to reclaim memory in time.
inPurgeable: Set to True, the Bitmap created using BitmapFactory is used to store the memory space of the Pixel, and can be recycled when the system memory is insufficient. When the application needs to access the Pixel of the Bitmap again, the system will call the decode method of the BitmapFactory again to regenerate Pixel array of Bitmap; when set to False, it means that it cannot be recycled.
inInputShareable: Set whether to copy deep, used in combination with inPurgeable. When inPurgeable is false, this parameter is meaningless; True: share a reference to the input data (inputStream, array, etc). False: a deep copy.
6. Use decodeStream instead of other decodeResource, setImageResource, setImageBitmap and other methods to load pictures.
the difference:
decodeStream directly reads the image bytecode and calls nativeDecodeAsset / nativeDecodeStream to complete the decode without using some extra processing in Java space, saving dalvik memory. However, because the bytecode is read directly, there is no processing, so it will not automatically adapt to the various resolutions of the machine. You need to configure the corresponding picture resources in hdpi, mdpi, and ldpi, otherwise on different resolution machines It is the same size (the number of pixels), the actual size of the display is not correct;
decodeResource will perform image adaptation processing according to the resolution of the machine after reading the image data, resulting in increased dalvik memory consumption;
decodeStream call Process: decodeStream (InputStream, Rect, Options)-> nativeDecodeAsset / nativeDecodeStream;
decodeResource call process: after finishDecode, call the additional Java layer's createBitmap method to consume more dalvik memory;
decodeResource (Resource, resId, Options)-> decodeResourceStream (Set inDensity and inTargetDensity parameters of Options)-> decodeStream () (finishDecode operation after completing Decode) finishDecode ()-> Bitmap.createScaleBitmap () (calculate scale based on inDensity and inTargetDensity)-> Bitmap.createBitmap ().
The combination of the above methods can reasonably avoid OOM errors.

9. Solve ScrollView nested GridView

Description: ScrollView nested GridView is used in the development. Since both controls have their own scroll bars, they will have problems when they come together, that is, the GridView will not display completely.
Reason: Since the parent control is automatically displayed according to the size of the child control, it is necessary to maximize the display processing of the child control.
Solution: The solution is to customize a GridView control, the code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class MyGridView extends GridView { 
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}

 

The code mainly modifies the onMeasure () method and sets the size to the maximum value of the int type. As for why you need to move right by two bits, the first two bits represent the value of the AT_MOST type.

10. Android implements the distance between the first and last rows of ListView or GridView from the edge of the screen

Description: The  distance between the first row and the last row of ListView or GridView is invalid.
Reason: The  default rows of ListView & GridView on Android are sticky.
Solution: Set android: clipToPadding of ListView or GridView = true, and then set the distance through paddingTop and paddingBottom.

11、Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 18 declared in library

Description: Manifest merger failed: uses-sdk: minSdkVersion 15 cannot be smaller than version 18 declared in library; Suggestion: use tools: overrideLibrary = ”xxx.xxx.xxx” to force usage.
Reason: This error is generally referred to the library The minimum version is higher than the minimum version of the project;
solution: add it to the tag in the AndroidManifest.xml file, where xxx.xxx.xxx is the third-party library package name, if there are multiple libraries with this exception, then split them with commas For example, this is done so that AndroidManifest.xml in the project and AndroidManifest.xml of the third-party library can be ignored when the minimum version limit is merged.

12. Jumping to the designated Taobao shop appears Getting net :: ERR_UNKNOWN_URL_SCHEME while calling telephone number from HTML page in Android

Description: Jumping to the specified Taobao shop resulted in the following error: Getting net :: ERR_UNKNOWN_URL_SCHEME while calling telephone number from HTML page in Android, prompting an unknown protocol.
Reason: Taobao ’s agreement is taobao://that the corresponding judgment should be made before jumping, if it is a web page, it needs to be replaced with an https://agreement.
Solution: You need to make a judgment before jumping to the Taobao shop, and then use the implicit jump to the designated shop. If the user has installed the Taobao client, the URL prefix is taobao://, if the Taobao client is not installed, the URL prefix is https://, the specific use code is as follows:

1
2
3
4
5
6
7
8
Uri uri;
if(ApkUpdateUtil.checkPackage(mContext, "com.taobao.taobao")){
uri = Uri.parse(AppConstant.BEAUTY_NOW_BUY_SCHEME);
} else{
uri = Uri.parse(AppConstant.BEAUTY_NOW_BUY_URL);
}
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

 

The path constant is as follows, just replace it with the address of your shop,

1
2
public static final String BEAUTY_NOW_BUY_URL = "https://shop***";
public static final String BEAUTY_NOW_BUY_SCHEME = "taobao://shop***";

 

The following is a static method to detect whether the application is installed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/ ** 
* Check if the application corresponding to the package name exists
* @param packageName
* @return
* /
public static boolean checkPackage (Context mContext, String packageName) {
if (packageName == null || "" .equals (packageName)) {
return false;
}
try {
mContext.getPackageManager (). getApplicationInfo (packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}

 

Development tools

1、SVN:Commit failed(details follow):svn: xxx is scheduled for addition, but is missing

描述:删除文件夹后点commit提交,但是提示以下错误: “svn: Commit failed (details follow): svn: ‘xxx’ is scheduled for addition, but is missing”。
原因:之前用SVN提交过的文件,被标记为”add”状态,等待被加入到仓库。若此时你把这个文件删除了,SVN提交的时候还是会尝试提交这个文件,虽然它的状态已经是 “missing”了。
解决:在命令行下用 “svn revert xxx –depth infinity”,在图形界面下,右键–Revert,选中那个文件或文件夹。这样就告诉SVN把这个文件退回到之前的状态 “unversioned”,也就是不对这个文件做任何修改。

2、Error:Cause: peer not authenticated

描述: Android studio 导入项目报 Error:Cause: peer not authenticated 异常
原因:主要是gradle版本对应不上导致的
解决:在project下的build.gradle文件中,将dependencies中的classpath对应的gradle版本改为1.3.0,再将repositories中的jcenter()改为jcenter{url “http://jcenter.bintray.com/"}

3、The connection to adb is down and a severe error has occured解决方案

描述:编译运行时报错:The connection to adb is down and a severe error has occured。
原因:其他应用占用了adb的进程端口,只要关闭相关进程就行。
解决:进入dos窗口,输入netstat -ano|findstr “5037”查看所有占用5037端口的进程ID,再输入tasklist|findstr “进程ID”,查找出对应的进程名称,进入任务管理器中关闭就行。

4、SVN无法读取current修复方法

描述: SVN提交记录时出现Can’t read file : End of file found,文件:repository/db/txn_current、repository/db/current,其中current记录当前最新版本号,txn_current记录版本库中版本号文件所存放文件夹。
原因:在提交文件时,svn服务器被强行关闭了,导致版本信息文件写入不成功,版本记录文件txn_current、current成了乱码。
解决:重新将正确的版本信息写入到current、txn-current文件,一般最新的那个版本会是错误的,只能回滚到上一版本。找到最新的版本,一般就是出错的那个版本,假设出错的是9010,一般可以从(\Repositories\ProjectName\db\revprops\X),其中的X是里面的文件夹名,几乎所有的版本号都能在这些目录里找到对应的文件名,找到最大的版本号9010,如果用记录本打开该文件是乱码,应该就是出错了,那就删除该文件,相应的,上一版本的版本号就是9009,对应的X一般就是9的文件夹。更新txn-current,里面写上X文件夹名”9”,然后回车换行并保存。更新current,里面写上9009,然后回车换行并保存。

5、android You may want to manually restart adb from the Devices view.

描述:编译运行时报错:You may want to manually restart adb from the Devices view.
原因: adb服务出问题导致的,一般需要重启该服务。
解决:在命令窗口中输入如下指令:

1
2
adb kill-server
adb start-server

 

6、Eclipse连接手机后DDMS一直显示connect attempts的问题

描述: Eclipse连接手机以后DDMS一直显示connect attempts,报Adb connection Error:An existing connection was forcibly closed by the remote host错误。
原因: Eclipse连接问题导致。
解决:添加系统环境变量:进入计算机属性,点击高级设置环境变量,新加变量ANDROID_SDK_HOME=D:\android\sdk(D:\android\sdk是android-sdk-windows的位置),Path追加%ANDROID_SDK_HOME%\tools。

7、Aborting commit:’XXXXXX’remains in conflict

描述:提交SVN代码时报冲突错误:Aborting commit:’XXXXXX’remains in conflict!
原因:在使用SVN时不可避免会出现代码冲突的问题,如果在更新代码时出现本地文件已经删除,而在SVN上却被别人修改导致更新出现冲突提交代码失败。
解决: Eclipse解决方式如下:
1、右击工程目录;
2、选择Team;
3、选择Show Tree Conflict(冲突树);
4、查看冲突列表,右击冲突文件;
5、标记为解决。
Android stuio解决方式如下:
1、右击工程目录;
2、选择Sunversion;
3、选择Commit Files;
4、显示提交文件列表,勾选需提交文件,如果文件标志位红色方框,则表示文件冲突,直接双击冲突文件进入下一步操作;
5、有两个选择,一个为文件以SVN为主,一个为文件以本地编写为主,如果该文件是需要被删除的,而本地已删除,则选择Accept Yours以本地为主,这样再提交就不会出现冲突。

8、编译报错:com.android.dex.DexIndexOverflowException:method ID not in [0, 0xffff]:65536

描述:编译时报如下错误:com.android.dex.DexIndexOverflowException:method ID not in [0, 0xffff]:65536,或者在安装时失败,并报错:dexopt failed on ‘/data/dalvik-cache/data@app@应用包名@classes.dex’ res = 65280(方法数)。
原因:这是由于编译时方法数越界和安装时的dexopt缓冲区大小不够存储该方法数导致的。
解决:在Gradle中的build文件中设置Android SDK Build Tools 21.1及以上版本,再在defaultConfig中设置multiDexEnabled true,接着还需要在dependencies中添加multidex的依赖:compile ‘com.android.support:multidex:1.0.0’,最后还需要在代码中加入支持multidex的功能,最终配置文件如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"//第一步

defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"

multiDexEnabled true//第二步
}

lintOptions {
abortOnError false
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile com.android.support:multidex:1.0.0//第三步
}

其中加注释部分为该设置所需,在代码中加入支持multidex功能的方法有如下三种方式:
方式一、在manifest文件中指定Application为MultiDexApplication;
方式二、让自定义的Application继承自MultiDexApplication;
方式三、在自定义的Application中实现attachBaseContext方法,在其中添加如下代码:MultiDex.install(this),该方法比onCreate方法先执行。

9、Gradle进行dex遇到内存不够用的情况

描述:java.lang.OutOfMemoryError: GC overhead limit exceeded;
原因:在Gradle进行dex的可能会遇到内存不够用的情况;
解决:在build文件的android属性下配置dexOptions下的javaMaxHeapSize大小即可,我这里配置2g;

1
2
3
dexOptions {
javaMaxHeapSize "2g"
}

 

10、提交svn时设置忽略文件无效

描述:在提交SVN时有时总是提示各种已经在.gitignore文件中设置忽略却无效的文件,如.gradle、.idea、build等文件夹下的文件。
原因:在Share Project to Subversion之前没有设置相关文件及文件夹的忽略,导致Share Project时全部添加到SVN库中。
解决:这种情况一般出现在本地已经有工程了,想提交到SVN库中,但是在第一次Share Project时没有设置忽略,因为第一次分享到SVN后就相当于把所有文件都提交到SVN库中了,这样不管你后面如何设置忽略都是无效的,因为SVN库中已经有这些文件了,所以只有在Share Project之前设置忽略才会真正忽略,设置忽略的操作步骤如下所示:
打开设置,在下图所示中找到版本控制忽略文件的条目,点击右上角的添加按钮添加忽略就行。最后再点击菜单栏中的VCS,选择Import into Version Control,再选择Share Project(Subversion)分享到SVN库中就可以了。

11、Error:(2, 0) Plugin with id ‘com.github.dcendents.android-maven’ not found

描述:在上传代码到jCenter库时需要配置

1
2
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

 

而在配置后构建出现Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not found错误。
原因:在使用插件功能时需要配置插件的支持来源及版本。
解决:找到project的build.gradle添加如下配置

1
2
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0"

 

完整配置如下:

1
2
3
4
5
6
7
8
9
10
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0"
}
}

 

然后重新构建即可。

12、 Failed to apply plugin [id ‘com.github.dcendents.android-maven’],Could not create plugin of type ‘AndroidMavenPlugin’.

描述:在使用Android Studio2.2时需要将gradle插件版本更新为classpath 'com.android.tools.build:gradle:2.2.0',构建工具版本更新为distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip,而在使用上传代码到jCenter功能时报错:Failed to apply plugin [id 'com.github.dcendents.android-maven'],Could not create plugin of type 'AndroidMavenPlugin'.
原因:AndroidMavenPlugin插件版本配置过低。
解决:将原来的配置

1
2
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0"

 

改成如下形式就行:

1
2
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0"

 

操作类

1、Javadoc中产生乱码的解决方法

描述:在生成javadoc文档或者在进行打包时出现“编码GBK的不可映射字符”错误。
原因:因为代码中有中文注释的缘故,这个还是比较常见的。
解决:
方式一:通过Android Studio界面操作生成JavaDoc文档,依次打开Tools->Generate JavaDoc->Other command line arguments设置为:“-encoding UTF-8 -charset UTF-8”;
方式二:通过配置module中的build.gradle文件,添加一个如下任务task:tasks.withType(JavaCompile) {
options.encoding = “UTF-8”
},这个构建时不会出现乱码,但是在查看生成的文档时会发现显示会乱码,找到原因是需要设置charset也为UTF-8,至今没找到怎么配置,如果有哪位仁兄知道怎么配置,麻烦评论告知下,万分感谢!

2、虚拟按键影响界面全屏显示

描述:在android4.0及其以上的版本中,出现了一个很屌的东西,叫做Navigation Bar,它和Status Bar一上一下相互交映,影响了我们的全屏。
原因:全屏显示时有时需要隐藏导航栏和虚拟按键,而虚拟按键是会根据你的触摸显示出来的,所以需要添加监听,在出现时直接强制隐藏。
解决:直接在当前Activity中添加如下代码就行:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private static Handler sHandler;
private final Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
int flags;
int curApiVersion = android.os.Build.VERSION.SDK_INT;
if (curApiVersion >= Build.VERSION_CODES.KITKAT) {
flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE;

} else {
flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
getWindow().getDecorView().setSystemUiVisibility(flags);

}
};

 

1
2
3
4
5
6
7
8
9
10
11
12
13
@Override
protected void onResume() {
super.onResume();
sHandler = new Handler();
sHandler.post(mHideRunnable); // hide the navigation bar
final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
sHandler.post(mHideRunnable); // hide the navigation bar
}
});
}

3、ListView点击条目无响应

描述:开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己定义listview,自己的Adapter去继承BaseAdapter,在adapter中按照需求进行编写,问题就出现了,可能会发生点击每一个item的时候没有反应,无法获取的焦点。
原因:原因多半是由于在你自己定义的Item中存在诸如ImageButton,Button,CheckBox等子控件(也可以说是Button或者Checkable的子类控件),此时这些子控件会将焦点获取到,所以常常当点击item时变化的是子控件,item本身的点击没有响应。
解决:使用descendantFocusability来解决,该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。
属性的值有三种:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
通常我们用到的是第三种,即在Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性就好了。

4、ActivityManager: Warning: Activity not started, its current task has been brought to the front

描述:用手机调试运行出现如下错误:ActivityManager: Warning: Activity not started, its current task has been brought to the front。
原因:该手机已经启动了相同名字的应用。
解决:关闭运行的应用重试就行。

5、Failed to fetch URL https://dl-ssl.google.com/android/repository/repository.xml

描述:在打开SDK Manager时,更新SDK时会出现如下错误:Failed to fetch URL https://dl-ssl.google.com/android/repository/repository.xml。
原因: dl-ssl.google.com在大陆封掉了。
解决:修改C:\Windows\System32\drivers\etc\hosts文件,添加一行:74.125.237.1 dl-ssl.google.com,保存并重新自动SDK Manager就OK了。

6、Android程序启动界面的短暂黑屏

描述:默认的情况下,android 程序启动时,会有一个黑屏的时期。
原因:系统默认的主题背景为黑色导致的。
解决:只要在入口activity加上android:theme=”@android:style/Theme.Translucent” 就可以解决启动黑屏的问题。

7、curl: (6) Couldn’t resolve host ‘android.git.kernel.org’

描述:通过Linux系统下载Android源码时提示错误:curl: (6) Couldn’t resolve host ‘android.git.kernel.org’ 。
原因:因为android.git.kernel.org网站被黑了,所以无法从该网站下载repo和android源代码了。
解决:换个网址下载,从https://www.codeaurora.org/网站下载android源码,具体方法如下:
下载repo并设置环境变量

1
2
3
$ curl "http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo"> ~/bin/repo
$ chmod a+x ~/bin/repo
$ PATH=~/bin:$PATH

 

下载android源码

1
2
3
4
$ mkdir WORKING_DIRECTORY
$cd WORKING_DIRECTORY
$ repo init -u git://codeaurora.org/platform/manifest.git -b gingerbread
$ repo sync

 

8、ListView取消点击效果

描述:用LIstView呈现的数据,类似于静态的那中,但是不要点击效果,默认的就是点击一下显示成橙黄色
原因:主要是实现点击没效果,其实是有效果只不过是透明给掩盖了
解决:在listview布局属性中添加如下属性android:listSelector=”@android:color/transparent”;

9、Didn’t find class “com.android.tools.fd.runtime.BootstrapApplication”

描述:提供的安装包在部分手机上安装点击后直接崩溃,提示Didn’t find class “com.android.tools.fd.runtime.BootstrapApplication”这样的错误
原因:Instant Run不支持5.0以下系统
解决:
方法一:直接Clean工程,再重新打包
方法二:禁止Instant Run功能,按照如下步骤操作即可:File –> Settings–>Build,Execution,Deployment –>Instant Run —> 不勾选 “Enable instant run”
方法三:修改编译环境,将相关的版本信息调低
classpath 'com.android.tools.build:gradle:2.2.0'修改为classpath 'com.android.tools.build:gradle:1.2.3';将buildToolsVersion '23.0.2修改为buildToolsVersion "21.1.2";找到.idea/gradle.xml文件,将<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.8" />修改为<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.4" />
出现如上问题,一般第一种方法都能解决,如果不行,禁用Instant Run功能即可,一般第三种方法不推荐使用。

 

Guess you like

Origin www.cnblogs.com/tc310/p/12707282.html