在集成环信sdk v3.0 用android studio 打开demo 遇见的一些问题
一.加载数度过慢
1) 一直卡在Building gradle project info这一步,主要原因还是因为被墙的结果。
解决方法: 修改gradle-wrapper.properties方式
1.随便找一个你之前能够运行的AS项目
2.打开项目的/gradle/wrapper/gradle-wrapper.properties文件
3.复制最后一行distributionUrl这一整行的内容,
例如:distributionUrl=https://services.gradle.org/distributions/gradle-2.8-all.zip,替换到你要导入的项目里的gradle-wrapper.properties文件中。
重启Android Studio,重新导入项目就可以了~~
2)一直卡在Gradle
解决方法:配置为离线模式
在Android Studio按一下方式找到 “Offline work” 选上钩点击OK
File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
解释
设为离线模式,不会去maven库下载依赖的包。也就是说:
例如 compile ‘com.tencent.bugly:crashreport:2.1.+’
那么不会每次都去检测使用有2.1.下的新版本
新依赖的包,因为无法下载包,不能通过编译
二 .运行时会报错
Error:Execution failed for task ':transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/ColorRes.class
如上错误就是app里边的jar 重复。我们只需找到 重复的删除就可以。我在这里取消了系统v7包
(注意:本目录结构相于比较乱,,一定要找到项目的Build. gradle)
//compile 'com.android.support:appcompat-v7:24.2.1'
如果以上无效果看是不是v4包。在Build. gradle 的android 里加上
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
具体Build. gradle如下
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.hyphenate.chatuidemo"
minSdkVersion 15
targetSdkVersion 24
multiDexEnabled true
}
//如果无效添加
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
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 = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':redpacketlibrary')
compile project(':EaseUI')
compile fileTree(include: '*.jar', exclude: 'android-support-multidex.jar', dir: 'libs')
//考虑到在eclipse中,直接使用源码
// compile ('com.anthonycr.grant:permissions:1.0'){
// exclude module: 'support-v4'
// }
//compile 'com.android.support:appcompat-v7:24.2.1'
}