OSC的Android客户端源码也开源很久了,一直想下载下来看看的奈何最近比较忙直到今天终于有时间clone下来研究研究了。
OSC的Android客户端项目使用的是Eclipse进行开发的,因为我现在的开发环境都是在Android studio下进行的,所以准备把OSC的项目转化为Android studio的项目。其实转化起来很简单的,之前也将自己很多的Eclipse的项目转化过Android studio项目。手动添加几个gradle文件分分钟就搞定了,OK下面开始转化。
从git.oschina.net clone下来的目录是这样的:
首先将libraries目录下的library项目拷出来放到osc-android-app同级目录下(注:因为 Android-ViewPagerIndicator-master项目的代码还在里面一层的 library目录下,所以将 library目录下的文件拷到Android-ViewPagerIndicator-master目录下)。
首先在osc-android-app同级目录也就是项目的根目录添加settings.gradle和build.gradle文件
settings.gradle:
include ':osc-adnroid-app',':Android-ViewPagerIndicator-master', ':PhotoView-library', ':UmengShareLib',":osc-android-app-appcompat-v7"
build.gradle:
buildscript { repositories { mavenCentral() } dependencies { //这里替换为你自己的gradle版本 classpath 'com.android.tools.build:gradle:1.0.0' } }
再为每个library项目下添加一个build.gradle文件:
build.gradle:
apply plugin: 'android-library' dependencies { compile fileTree(dir: 'libs', include: '*.jar') } android { compileSdkVersion 19 //替换为当前已有的build tools版本 buildToolsVersion "21.1.2" 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') } }
然后为osc-android-app主项目添加一个build.gradle:
apply plugin: 'android' dependencies { compile fileTree(dir: 'libs', include: '*.jar') compile project(':Android-ViewPagerIndicator-master') compile project(':PhotoView-library') compile project(':UmengShareLib') compile project(':osc-android-app-appcompat-v7') } android { compileSdkVersion 19 buildToolsVersion "21.1.2" compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } 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') } }
OK,差不多已经完成了。
打开Android studio-->File-->Open 选中项目根目录我们创建的build.gradle点击OK打开我们的项目。
项目编译的时候会报几个错误:
1、主项目的资源文件colors文件里有重复定义的颜色名称white和blue。解决办法:将white删除一个,将日历的blue修改个名称,然后将使用的地方\res\color\date_picker_selector.xml改一下
2、welcome.png不是png文件,虽然文件后缀是png但是其实不是标准png图片,Android studio检测比较严格 解决办法:将welcome.png用图片编辑器打开然后另存为png图片即可
3、在AndroidManifest.xml里的最后提示找不到最后两个activity
<activity android:name="com.tencent.tauth.AuthActivity" android:launchMode="singleTask" android:noHistory="true" > <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="tencent100942993" /> </intent-filter> </activity> <activity android:name="com.tencent.connect.common.AssistActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
这个应该是QQ分享或者授权的activity,不知道为啥报错,暂且将它先注释掉吧。
将上述几个问题修改以后然后rebuild一下,编译正常后,点击运行就能正常的运行了。
亲测能正常运行