Studio使用问题汇总

来源:互联网 发布:淘宝美工设计培训 编辑:程序博客网 时间:2024/06/06 15:48

Eclipse迁移到Android Studio

从Eclipse导出

1、更新你的Eclipcs的ADT插件(ADT的版本必须大于等于22.0)
查看android ADT 版本号:
启动eclipse,Help > About Eclipse SDK,在eclipse SDK对话框下面单击机器人图标,会有Android Development Toolkit
Version: 23.0.7.2120684
2、在Eclipse中,选择Flie->Export
3、弹出的对话框中,点击Android并选择Generate Gradle build files
4、选择你要导出的工程后点击Finish
你选择导出的工程依旧在原来的路径下,只是多了一个为Android Studio准备的build.gradle文件

导入到Android Studio中

1、在Android Studio中,关闭你当前的工程。页面会跳到欢迎页面。
2、选择Import Project
3、定位到你想要导入的工程的目录,选择build.gradle文件
4、在弹出来的对话框中,不进行任何更改直接点OK
这时你的工程就被导入到Android Studio中了。
注意:即使工程没有生成build.gradle文件,你也可以导入到Android Studio中。Android Studio也可以使用Ant来进行编译工程。然后,为了更好的使用其他的功能(如:build variants),我们强烈建议你使用ADT插件生成一个gradle文件或者在Android Studio中直接写gradle文件。更多的内容,可以戳这:http://tools.android.com/tech-docs/new-build-system/user-guide。
原文地址:http://developer.android.com/sdk/installing/migrate.html

问题1(65K的问题)

报错信息
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.mapapi.model.a) that doesn’t come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any “-target” type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.mapapi.model.b) that doesn’t come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any “-target” type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.platform.comapi.b) that doesn’t come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended

这个是由于65K的问题
解决办法:
在项目build.gradle这里添加这句就可以了。
defaultConfig {
multiDexEnabled true
}

问题2(keepattributes EnclosingMethod)

Error:associated EnclosingMethod attribute. This class was probably produced by a
这里写图片描述
-keepattributes EnclosingMethod

问题3(这是jar包重复)

Error:Execution failed for task ‘:app:transformClassesWithJarMergingForDebug’.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat.class
这是jar包重复
各个收费平台sdk 都有android-support-v4.jar
如果项目用了google服务compile ‘com.google.android.gms:play-services:8.4.0’
就报这个错误了 ,目前百度, 360 游戏sdk都有这个问题 其他sdk还没迁移
解决:直接把sdk libs 中 android-support-v4.jar 删除

问题4(studio item标签下不能使用showAsAction属性)

写ActionBar的时候 item标签下的 android:showAsAction=”” 属性无法使用, 找了半天发现原来是V7支持包的一个BUG,我的默认加载的支持包就是v7
解决办法: 1. 修改支持包,把v7改掉
修改路径:build.gradle(Module:app) 在 dependencies { } 下面
2. 将android:showAsAction=”” 中的android 换掉,改成自定义的名字
方法如下 ,我使用的名字是ActionBar2
menu 布局文件下:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ActionBar2="http://schemas.android.com/apk/res-auto">

ActionBar2 是自己定义的字符段 然后:
android:showAsAction=””
变为 :
ActionBar2:showAsAction=”ifRoom”
就可以了
有个小技巧就是直接写
ActionBar2:showAsAction=”ifRoom”
鼠标定位在 AcrionBar2 上直接alt+回车 连敲回车 ide会自动帮你补全

问题5(anim只能放动画,其他的xml放到drawable)

写Selector时,Selector文件必须放在Drawable文件夹下,同时所引用的资源文件(比如图片)也必须放到Drawable文件夹下
尽量别用.9图片,有的话一定是完整的.9图片,因为Studio对.9图片审核比eclipse严格很多

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/actionsheet_top_pressed" android:state_pressed="true"/>    <item android:drawable="@drawable/actionsheet_top_normal"/></selector>

问题6(mipmap-xxx与单独的drawable目录)

原生图片放在mipmap 里面 drawable主要放一些放一些自定义形状和按钮变色之类的xml
4.3 google强烈建议使用mipmap装图片。把图片放到mipmaps可以提高系统渲染图片的速度,提高图片质量,减少GPU压力。
但是mipmap中创建selector的xml时报错。
指向drawable目录右键可创建drawable resource file ,可以创建selector。
但是引用mipmap目录下的图片文件时又会报:
Error:(3) No resource identifier found for attribute ‘mipmap’ in package ‘android’
所以选择创建selector时,我选择将selector中用到的图片文件放在 drawable目录下。由于适配问题,最终将mipmap目录全部替换成drawable目录,仍旧用旧方法。
可解决问题。

问题7(Error:Execution failed for task ‘:App:mergeDebugResources’.)

Error:Execution failed for task ‘:App:mergeDebugResources’.
Error: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
Try code on your module build.gradle:
android {
// …
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
// …
}

问题8(Error running app: Instant Run requires ‘Tools | Android | Enable ADB integration’ to be enabled.)

Enable your ADB Integration. Go to Tools –> Android –> set checked in Enable ADB Integration

问题9(Error:No service of type Factory available in ProjectScopeServices.)

直接将’ classpath com.github.dcendents:android-maven-gradle-plugin:1.3’更新到1.4.1就可以解决问题了。

问题10(Error:Error: Expected resource of type id [ResourceType])

android :
lintOptions {
disable “ResourceType”n
}

问题11(Android Studio failed to find build tools revision 19.1.0)

是因为该开源库对应的Build Tools的版本你的AS里面没有。解决方法是点击他的链接进行下载。或者更改每个model里面的app/build.gradle文件中的 buildToolsVersion “21.1.1” 为本机里面有的Build Tolls版本。
也可以从SDK Manager中手动更新SDK

问题12(Fragment:关于Avoid non-default constructors in fragments的错误)

在android开发中,写了一个关于继承Fragment的类时,如果有重载构造函数时,会提示“Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead”的错误,这时。在类的前面加上@SuppressLint(“ValidFragment”)即可。

问题13(java.lang.OutOfMemoryError: GC overhead limit exceeded)

dexOptions {
javaMaxHeapSize “4g”}

问题14(Plugin with id ‘com.novoda.bintray-release’ not found)

dependencies { classpath ‘com.android.tools.build:gradle:1.5.0’ //添加下面这行代码就OK了
classpath ‘com.novoda:bintray-release:0.3.4’

问题15(Failed to resolve: com.github.franmontiel:PersistentCookieJar:v0.9.3)

project.build
这里写图片描述

问题16(“pull_to_refresh_pull_label” is not translated in “en” (English) [MissingTranslation] (打包的时候))

解决办法
android {

lintOptions{
checkReleaseBuilds false
abortOnError false
}
}

问题17(Error:A problem was found with the configuration of task ‘:app:packageRelease’)

Error:A problem was found with the configuration of task ‘:app:packageRelease’.
File F:\code_p2p_new\jiucaitong2.0\StudioCode\studio2.0\app\build\intermediates\res\resources-release-stripped.ap_’ specified for property ‘resourceFile’ does not exist.

shrinkResources false //改为false 就解决了
shrinkResources为true在打包时会删除没有用到的资源。但是如果项目中有些资源是根据用户使用情况动态配置的,那么打包后会出问题。

问题18(java.io.IOException: Could not delete path)

我是在操作svn出现的这种情况,解决的办法也简单就是找到提示的目录D:\ProjiectName\app\build\intermediates,先退出AS,然后删除builde这个文件夹,重新打开AS就搞定了,然后可以看到builde重新生成正常的了。