Android Studio开发环境中的问题

记录下我在Android Studio环境下遇到的各种问题:

1、导入原来的Eclipse工程,编译失败

提示各种各样的错误,大概有这几个:

(1)代码中存在某些类继承了apache http相关类库中的类,编译提示找不到这些类,比如 org.apache.http.impl.conn.DefaultResponseParser

 【原因】

Android 6.0 中移除了Apache HTTP Client 相关的类:
Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption.

【对策】

To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:
android {
    useLibrary 'org.apache.http.legacy'
}

在build.gradle中加入以上配置,gradle会下载相关依赖库 org.apache.http.legacy.jar,该库包含android.net.* 和org.apache.* 类库。


(2)提示找不到符号 import android.support.v4.util.ArrayMap

【原因】

使用了Android Studio默认的依赖配置compile files('libs/android-support-v4.jar') ,其中没有ArrayMap这个类

【对策】

使用原来eclipse项目中的android-support-v4.jar

依赖配置改为

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

直接使用libs下的jar包


(3)提示布局文件找不到自定义view定义的属性

【原因】

在布局文件中引用自定义view时,通常都会使用命名空间,其uri一般为 xmlns:custom="http://schemas.android.com/apk/res/包名"

gradle项目定义命名空间时uri推荐使用"http://schemas.android.com/apk/res-auto" 取代之前包含包名的uri

【对策】将原来的命名空间uri改成"http://schemas.android.com/apk/res-auto"


(4)Error:warning: Ignoring InnerClasses attribute for an anonymous inner class .......

网上说需要修改混淆配置 比如-dontoptimize 等,但是改了后没效果。在Debug模式下,配置不混淆就可以了。

buildTypes {
        debug {
            minifyEnabled false
        }

}


(5)Cause: com.android.dex.DexIndexOverflowException: Cannot merge new index 65542 into a non-jumbo instruction!

在 build.gradle中加以下配置

android {

dexOptions {
        jumboMode true

    }

}


经过以上几个修改最终可以编译成功!

如果需要保持原来Eclipse项目的目录结构,可以参考官网指导:

http://tools.android.com/tech-docs/new-build-system/intellij_to_gradle
http://tools.android.com/tech-docs/new-build-system/migrating-from-intellij-projects


2、运行APK出现FC,找不到so文件

错误:java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/data/....so" not found 

【原因】

没有正确引入so库文件

【对策】

1.如果是Android Studio项目默认目录结构,只需要在main目录下新建jniLibs目录,把so文件放到该目录下
2.如果是eclipse目录结构,除了在根目录新建jniLibs目录,还需要在build.gradle文件中sourceSets这个设置中添加jniLibs.srcDirs = ['jniLibs']

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    useLibrary 'org.apache.http.legacy'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']

            jniLibs.srcDirs = ['jniLibs']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    dexOptions {
        jumboMode true
    }
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值