# android-app **Repository Path**: sunrix/android-app ## Basic Information - **Project Name**: android-app - **Description**: OSChina Android 客户端源码 AndroidStudio3.2.1版本构建,gradle及依赖库更新为当前最新(2018/11/22) - **Primary Language**: Android - **License**: Not specified - **Default Branch**: master - **Homepage**: http://www.oschina.net/p/oschina-android-app - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3665 - **Created**: 2019-06-05 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## OSChina Android > 本项目为`fork`开源中国的`android`版本`4.1.7`最新开源代码,并使用`Android Studio 3.2.1`版本,更新`gradle`配置为当前最新态`4.10`(在项目下的`gradle`目录内,`wrapper`文件夹的`gradle-wrapper.properties`内配置),编译运行成功。希望有助于大家研究学习。原项目地址 ## 源码升级配置注意 `clone`官方的源码之后,发现好多依赖库,以及配置都比较老旧,而且在新版的`AndroidStudio`上是无法运行。所以尝试解决问题,编译并运行OK,改变点记录如下: 1. 修改编译版本 ```groovy //改为28编译 ext { compileSdkVersion = 28 buildToolsVersion = "28.0.3" applicationId = "net.oschina.app" minSdkVersion = 19 targetSdkVersion = 28 versionCode = 417 versionName = "v4.1.7 (1806190800)" supportVersion = '28.0.0' } ``` 2. 修改`gradle`以及`dexcount`版本 ```groovy buildscript { repositories { google() jcenter() } dependencies { //更新gradle版本为3.2.1,以及dexcount版本为0.6.2 classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2' } } allprojects { repositories { //添加阿里云的源,下载快速 maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } jcenter() mavenCentral() google() maven { url 'https://dl.bintray.com/oschinaapp/maven/' } maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } maven { url 'https://jitpack.io' } } } ``` 3. 解决`Dimensions`错误 ```groovy //在app目录下的buidle.gradle文件内,添加如下,在android{}闭包内 flavorDimensions "versions" ``` 4. 解决`gradle版本升级引起的错误` ```groovy //在android{}闭包下,修改生成apk的命名配置 // rename the apk with the version name android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = "osc-android-${variant.versionName}-${variant.productFlavors[0].name}.apk".toLowerCase() } } ``` 5. 解决`com.android.tools.r8.utils.AbortException: Error: Static interface methods are only supported starting with Android N` ```groovy //android{}闭包内添加 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } ``` 6. `theme.xml`错误,引起编译错误 ```xml ``` 7. `AndroidManifest.xml`中有一条重复的`meta-data`百度的数据配置,删除。 8. 配置`BuildConfig`应用到的`key`,在`local.properties`文件中 ```properties ## 替换为开发者在OSChina上申请的openapi的key AES_KEY = 1234567891234567 AES_IV = 9876543217894561 VIOLET_PASSCODE = 123 ``` 9. 更新`dependencies`,使用`androidx`支持库 ```groovy //更新support库为androidx,更新butterknife为9.0版本 dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') //noinspection GradleCompatible,GradleDependency implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'com.google.android.material:material:1.0.0-rc01' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0-rc01' implementation project(':open') if (propertyHaveDebugCompile) { implementation propertyDebugCompile } androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha3', { exclude group: 'com.android.support', module: 'support-annotations' }) implementation 'com.github.chrisbanes.photoview:library:1.2.4' implementation 'com.loopj.android:android-async-http:1.4.9' //noinspection GradleDependency implementation 'com.jakewharton:butterknife:9.0.0-rc2' annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc2' implementation 'com.google.zxing:core:3.3.0' implementation 'com.joanzapata.android:android-iconify:1.0.9' implementation 'com.makeramen:roundedimageview:2.1.1' implementation 'pub.devrel:easypermissions:0.3.0' implementation 'com.github.bumptech.glide:glide:3.7.0' //noinspection GradleDependency implementation 'de.hdodenhof:circleimageview:2.0.0' implementation 'com.google.code.gson:gson:2.8.2' implementation 'com.upyun:upyun-android-sdk:2.0.5' //noinspection GradleDependency // implementation 'com.umeng.analytics:analytics:latest.integration' //noinspection GradleDependency implementation 'com.baidu.mobstat:mtj-sdk:latest.integration' //noinspection GradleDependency implementation 'androidx.multidex:multidex:2.0.0' implementation 'net.oschina.common:common:0.2.1' implementation 'com.belerweb:pinyin4j:2.5.1' implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' implementation 'com.hyman:flowlayout-lib:1.1.2' implementation('com.github.mcxtzhang:SwipeDelMenuLayout:V1.2.5') { exclude group: 'com.android.support:appcompat-v7', module: 'support-v4' } testImplementation 'junit:junit:4.12' } ``` 10. 更新`butterknife`并修改代码中的`@Bind`为`@BindView`,其中有一个使用了`@BindViews`以及低版本有个`ButterKnife.unbind(this);`这个函数,可以去掉。 修改之后,基本便可以正常运行,如果不配置开发者申请的key,则会拉取不到内容信息。在此,感谢**开源中国**,给大家一个学习交流的平台!