Android Studio开发中常见问题及解决(二)

1、associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is *not* an inner class.
出现这种类型警告和错误,那么jar重复,没有用到的jar,jar里面的包名与xxx的包名重复,或者是jar版本太老等,反正是jar里面的class文件转为dex的时候出错,解决办法是删除jar包,网上找对应的源码,或者用工具把jar转为源码形式来调用解决掉所有警告,然后加上multidex处理65536的问题,因为方法越界也会出现类似此错误,完了即可编译通过。。


2、查看Android设备上的数据库
SQLScout,在 Android studio 内连接并操作 Android 设备上 sqlite 数据库。


3、解决Android Studio下Element layer-list must be declared问题
最近将一个项目从Eclipse转到Android Studio。项目中使用了环信demo中的一些xml资源,转换后发现color资源文件夹下诸如layer-list或者shape等标签报Element xxx must be declared错误,大意就是layer-list或者shape这些标签没有定义。


layer-list或者shape等这些标签是常用的标签,Android Studio居然报没有定义错误,在Eclipse中却没有这个问题。网上不少人说这是Android Studio的一个bug,事实正相反,这是Android Studio的优点。


对于这个问题,首先要了解layer-list、shape等这些标签是什么东西。每一种标签都有对应的资源类,layer-list、shape等等标签代表的其实是个drawable资源。layer-list最终会解析为LayerDrawable,shape会解析为ShapeDrawable,其它的标签类似。由此可以看出layer-list或者shape等资源是drawable资源,应该放到drawable资源文件夹下。color资源不包括drawable资源,当然没有定义drawable类型的标签。


Eclipse不像Android Studio,对资源类型的检查没有那么严格,所以没有报错误。我觉得这倒是Android Studio的优点,是什么资源就应该放到什么位置,不容易让人产生疑惑。所以在Android Studio下的解决方法就是把这些资源文件移动到drawable资源文件夹下,这个问题解决。


4、Error running app:No target device found
出现这种情况其实是在Android Studio初始化的过程中,Android Monitor程序没被启动而无法识别USB线所连接的设备所致。
解决方法很简单:



选择下方的Android Mointor选项,Android Studio会帮你自动识别查找设备。这样就完美的解决了这个问题


5、查看Windows下端口占用情况
(1)在开始-运行,输入CMD打开命令行界面,输入命令
netstat -ano | findstr "80" (注80是你想要看查看的端口号)
就会输出包含80端口使用的情况
具体对应的行是
协议    本地地址        外部地址          状态          PID


(2)如果想看某个进程具体是哪个进程可以使用下面命令
tasklist | findstr "5584"(注 5584是进程的id即PID)


6、Android代码混淆,打包时出现如下异常:
Build->Generate Signed APK时却碰到了一个Error:
Error:Execution failed for task ':app:packageRelease'.  
> Unable to compute hash of G:\coding\XXXXXAPP\app\build\intermediates\classes-proguard\release\classes.jar 


解决方法:查看一下proguard warning,因为error之前,编译的时候前面肯定有warning. 翻了一下,果然发现很多warning.
接下来只要在proguard-rules.pro加下对应库的dontwarn即可。
-dontwarn org.apache.http.**


其实原因可以在warning下面找到:
Warning:there were 42 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
包括解决方案。所以大家伙在碰到问题时,可以多看看提示,里面或许就有答案。


7、Error:(53, 35) 错误: 无法访问HttpRequestBase 找不到org.apache.http.client.methods.HttpRequestBase的类文件

解决方案:在build.gradle中添加
android {
    useLibrary 'org.apache.http.legacy'


8、问题:Cannot reload AVD list: cvc-enumeration-valid: Value '280dpi' is not facet-valid with respect to enumeration
 '[ldpi, mdpi, tvdpi, hdpi, xhdpi, 400dpi, xxhdpi, 560dpi, xxxhdpi]'. It must be a value from the enumeration.


 Error parsing D:\studio\sdk\system-images\android-22\android-wear\armeabi-v7a\devices.xml


 cvc-enumeration-valid: Value '280dpi' is not facet-valid with respect to enumeration '[ldpi, mdpi, tvdpi, hdpi,
 xhdpi, 400dpi, xxhdpi, 560dpi, xxxhdpi]'. It must be a value from the enumeration.


解决方案:用/sdk/tools/lib/devices.xml去替换system-images\Android-22\android-wear\x86\devices.xml和system-images\android-22\android-wear\armeabi-v7a\devices.xml中的devices.xml,这样就可以解决


9、AndroidStudio中利用svn提交删除文件
Version Control-->Local Changes
Locally Deleted Files-->Remove from VCS-->Commit Changes


10、AndroidStudio配置SVN以及使用代码管理
http://www.it165.net/pro/html/201508/51801.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值