Android开发问题汇总(二)
1.Error running app: Default Activity not found
A: 问题的原因是 AndroidManifest.xml 文件配置的有问题。正确的样例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
2. How to rename java package in Android Studio?
A:Android Studio Rename Package
3.No service of type Factory available in ProjectScopeServices
A:Change maven gradle plugin version to 1.4.1 in project build.gradle file
1 2 3 4 |
|
ReferenceNo service of type Factory available in ProjectScopeServices
4.Android Gradle cannot find symbol class Gson
A:In my case, I just added this line:
1
|
|
on my app build.gradle file.
By now 2.7 is last current available version according to: https://mvnrepository.com/artifact/com.google.code.gson/gson
Please check this repository to be sure you are using last available version.
Reference:Android Gradle cannot find symbol class Gson
5.Gradle sync failed: The SDK Build Tools revision (19.0.0) is too low for project ‘:app’. Minimum required is 19.1.0
A:设置更新版本的Build Tools:
1 2 3 4 5 6 7 8 9 10 11 |
|
6.Gradle sync failed: Could not find method android() for arguments [build_5v1bwdgcgpex8ek4ayinac3qa$_run_closure3@6518ea53] on root project ‘ActionBarDemo’ of type org.gradle.api.Project.
A:Root project gradle hasn’t method android(), so remove it and setting in module gradle.
7.Failed to resolve: junit:junit:4.12
A:It happens HTTPS is blocked by proxy, so we have to disable proxy.
1 2 3 4 5 6 |
|
Reference:Failed to resolve: junit:junit:4.12
7.Error:Please select Android SDK
A:应用的Run 标红,打开弹出的对话底部提示error please select Android SDK.工程是从 eclipse 迁移过来的,target SDK 一开始是没安装的,安装之后标红依然没有消失。File > Project Structure… > Properties > Compile SDK Version 选择一个之前安装好的版本,工程构建之后标红消息,之后再选择刚安装的 target SDK 作为Compile SDK Version, 工程自动重新构建成功,标红消息。应该是安装 SDK 版本之后没有立即生效,连带 android.app 包都找不到。
8.unknown attr app:popuptheme
A:The reason is miss relate name space:xmlns:app=“http://schemas.android.com/apk/res-auto”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
9.How to get Activity’s content view?
A:
1 2 3 4 5 6 7 |
|
Reference:How to get Activity’s content view?
10.Conversion to Dalvik format failed with error 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
A:This android project dependent on serveral java projects, when I change these java project’s jre from 1.8 to 1.6, it works. The deep reason isn’t clear.
11.Make the Input Box Fill in the Screen Width
A: Setting the width to zero (0dp) improves layout performance because using “wrap_content” as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.
1 2 3 4 5 |
|
Reference:Building a Simple User Interface
12. TabHost.TabSpec is not an enclosing class.
A:TabHost.TabSpec is not static so it requires an instance of the outer class.Using TabHost’s newTabSpec method instead of new TabHost.TabSpec.
Reference:Is not an enclosing class Java
13. com.android.ide.common.process.ProcessException: Failed to execute aapt
A: The reason is buildToolsVersion doesn’t match compileSdkVersion, correct it in module gradle fix problem.
Reference:解决com.android.ide.common.process.ProcessException: Failed to execute aapt
14. What is the difference between android:gravity and android:layout_gravity?
A: The difference between android:gravity and android:layout_gravity is that android:gravity positions the contents of that view (i.e. what’s inside the view), whereas android:layout_gravity positions the view with respect to its parent (i.e. what the view is contained in).
Reference:
How to Position Views Properly in Layouts
15. Expected Resource of type ID
A:It is a editor validation error as this is not a common way to deal with ids. So if your app supporting API 17 or higher, you can call View.generateViewId as
1
|
|
and for API < 17
- Open your project’s res/values/ folder;
- Create an xml filed called ids.xml with following content:
1 2 3 4 5 |
|
then in your code,
1 2 3 |
|
Reference:Android - Expected Resource of type ID