开发过程中,所遇到的一部分问题

总结目前所遇到的部分问题,并已解决,请多多指教:
1、由于使用的是老版本的框架,今天把项目从eclipse转移到了studio,遇到了各种问题:
1、sdk版本不同,修改每个项目下面的build.gradle文件中的编译sdk版本号
2、老的httpCilent请求类,显示19以后studio不再使用,所以谷歌也给出了方案:
/——————————————————–/
//官方原文
Apache HTTP Client Removal
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—>clean project之后,重新编译就会提示了。
3、如果你是使用多项目引用,那么每个项目下的build.gradle都要做一下处理,修改编译sdk版本号等信息,另外不要忘了一定要修改整个工程下的build.gradle,以及gradle—>wrapper文件夹下的gradle-wrapper.properties文件中修改gradle版本
4、导入Project的出现:

Error:(1, 0) Your project path contains non-ASCII characters. This will most likely cause the build to fail on Windows. Please move your project to a different directory. See http://b.android.com/95744 for details.

This warning can be disabled by using the command line flag -Dcom.Android.build.gradle.overridePathCheck=true, or adding the line ‘com.android.build.gradle.overridePathCheck=true’ to gradle.properties file in the project directory
项目工程路径不能为中文的
5、java.lang.IllegalStateException: Multi dex requires Build Tools 21.0.0 / Current: 19.1
把 build.gradle修改为:
android {
compileSdkVersion 20
buildToolsVersion ‘21.0.0’

}

并确保你得Build Tools有21.0.0
6、Suggestion: add ‘tools:replace=”android:theme”’ to element at manifestMerger155308228

AS的Gradle插件默认会启用Manifest Merger Tool,若Library项目中也定义了与主项目相同的属性(例如默认生成的android:icon和android:theme),则此时会合并失败,并报上面的错误。

解决方法有以下2种:

方法1: 在Manifest.xml的application标签下添加tools:replace=”android:icon, android:theme”(多个属性用,隔开,并且记住在manifest根标签上加入xmlns:tools=”http://schemas.android.com/tools”,否则会找不到namespace哦)

方法2: 在build.gradle根标签上加上useOldManifestMerger true (懒人方法)

/***调用系统相机拍照以及取出照片相关问题***/
取图片问题(小米问题)

private void openAlbum(int number) {
        if (image_path.size() == number) {
            Intent intent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
            startActivityForResult(intent, RESULT_CANCELED);
        }

    }

由于小米和其他手机相册路径不同,发现取出来的路径为null,所以需要另外对待,下面就是其中的一个方案

if (data != null) {    
    Uri uri = data.getData();    
    if (!TextUtils.isEmpty(uri.getAuthority())) {    
        Cursor cursor = getContentResolver().query(uri,  
                new String[] { MediaStore.Images.Media.DATA },null, null, null);    
        if (null == cursor) {    
            Toast.makeText(this, "图片没找到", Toast.LENGTH_SHORT).show();    
            return;    
        }    
        cursor.moveToFirst();    
        path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));  
        cursor.close();    
    } else {    
        path = uri.getPath();    
    }    
}else{    
    Toast.makeText(this, "图片没找到", Toast.LENGTH_SHORT).show();    
    return;    
}   

7、导入工程时出现 Error:(20, 0) Gradle DSL method not found: ‘android()’
Possible causes:

  • The project ‘LNotifications’ may be using a version of Gradle that does not contain the method.
    Gradle settings
  • The build file may be missing a Gradle plugin.
    Apply Gradle plugin
  • 解决方法:

在最外层的Gradle中,删除如下的语句:
android {
compileSdkVersion 23
buildToolsVersion ‘23.0.2’
}

8、编译时出现Error:(25, 0) Gradle DSL method not found: ‘compile()’
Possible causes:

解决方法:

在最外层的Gradle中,删除如下的语句:
dependencies {
compile files(‘libs/xUtils-2.6.14.jar’)
}

9、编译出错:
Error:Execution failed for task ‘:app:mergeDebugResources’.

D:\workspace5\Boke\app\src\main\res\drawable\custom_Animation_progress_bar.xml: Error: ‘A’ is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore
解决方法:

你的项目中存在中文命名,将项目中对应的中文命名改为英文即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值