Last active
December 21, 2015 08:48
-
-
Save wuyexiong/6280305 to your computer and use it in GitHub Desktop.
1.ndk动态库打包
2.多渠道编译
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.regex.Pattern | |
| apply plugin: 'android' | |
| dependencies { | |
| compile fileTree(dir: 'libs', include: '*.jar') | |
| compile project(':omusic-library') | |
| } | |
| task copyNativeLibs(type: Copy) { | |
| from fileTree(dir: 'libs', include: '**/*.so' ) into 'build/native-libs' | |
| } | |
| tasks.withType(Compile) { | |
| compileTask -> compileTask.dependsOn copyNativeLibs | |
| options.encoding = "UTF-8" | |
| } | |
| clean.dependsOn 'cleanCopyNativeLibs' | |
| tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> | |
| pkgTask.jniDir file('build/native-libs') | |
| } | |
| def buildOutputApkName() { | |
| def apkName = "OM_TV_" + android.defaultConfig.versionName + "_" + getChannel("AndroidManifest.xml"); | |
| return apkName; | |
| } | |
| android { | |
| compileSdkVersion 16 | |
| buildToolsVersion "17.0.0" | |
| defaultConfig { | |
| versionCode 3 | |
| versionName "2.0.0" | |
| minSdkVersion 8 | |
| targetSdkVersion 17 | |
| project.archivesBaseName = buildOutputApkName(); | |
| } | |
| signingConfigs { | |
| omusic { | |
| storeFile file("xx") | |
| storePassword "xx" | |
| keyAlias "xx" | |
| keyPassword "xx" | |
| } | |
| } | |
| buildTypes { | |
| release { | |
| runProguard true | |
| proguardFile 'proguard-project.txt' | |
| signingConfig signingConfigs.omusic | |
| } | |
| } | |
| sourceSets { | |
| main { | |
| manifest.srcFile 'AndroidManifest.xml' | |
| java.srcDirs = ['src'] | |
| resources.srcDirs = ['src'] | |
| aidl.srcDirs = ['src'] | |
| renderscript.srcDirs = ['src'] | |
| res.srcDirs = ['res'] | |
| assets.srcDirs = ['assets'] | |
| } | |
| // 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') | |
| } | |
| } | |
| def getChannel(manifestLocation) { | |
| def manifestFile = file(manifestLocation) | |
| if (!manifestFile.exists()) { | |
| return -1 | |
| } | |
| def pattern = Pattern.compile("android:value=\"(.*)\" android:name=\"UMENG_CHANNEL\"") | |
| def manifestText = manifestFile.getText() | |
| def matcher = pattern.matcher(manifestText) | |
| matcher.find() | |
| def channel = matcher.group(1) | |
| return channel; | |
| } | |
我的解决方案:
1.理解build.gradle中自定义task的目的。对于so库,我理解的目的就是copy到\build\native-libs\中。至于gradle如何使用\build\native-libs我不是很了解。
2.了解目的后,那么我们就可以采用很多方案解决这个问题(如果build.gradle能够做到那就更好了)。不行的话,手动copy到\build\native-libs\就可以解决这个问题。也可以自己写个python脚本去copy。毕竟我们经常会gradle clean。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
昨天我提出上面的这个问题,最终解决了。方法比较笨,如果其他人也遇到同样的问题,希望能够来你这里。