美文网首页
android打包aar、发布签名包、混淆

android打包aar、发布签名包、混淆

作者: 墨色尘埃 | 来源:发表于2018-09-29 09:24 被阅读18次

1、打包aar的工程
AndroidManifest.xml中不能有<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>,如果有这个的话,在别的项目引用这个aar包之后,手机上会有两个图标
build.gradle中不能有apply plugin: 'com.android.application',需要改为apply plugin: 'com.android.library'

android打包aar步骤.png
arr包路径.png
image.png
别的项目引用aar包
aar包放在libs包下,同时build.gradle文件中引入
image.png
image.png

2、关于地图引用百度sdk
引用的jar包有如下:

image.png
BaiduLBS_Android.jar放在libs包下,arm64-v8a/armeabi/armeabi-v7a放在JniLibs包下
image.png

3、目前有maputil、CommonReportPage可以打包为aar
E:\ASProject\androidcommon
E:\ASProject\010trunk\CommonReportPage

4、android打包签名包
Build→Generate Signed APK,注意versionnameversioncode
也要改

    defaultConfig {
        applicationId "com.jsptpd.srfa"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 27
        versionName "0.2.7"
        ndk {
            abiFilters "armeabi", "armeabi-v7a"
        }
    }
image.png

5、android打包签名包,混淆
build.gradle文件中引入proguard-rules.pro

    buildTypes {
        release {  //发布版本使用混淆文件
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

    }

完整build.gradle(Module:app)

apply plugin: 'com.android.application'
//apply plugin: 'android-apt'

def AAVersion = '4.0.0'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.jsptpd.srfa"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 27
        versionName "0.2.7"
        ndk {
            abiFilters "armeabi", "armeabi-v7a"
        }
    }
    buildTypes {
        release {  //发布版本使用混淆文件
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
//    repositories {
//        flatDir {
//            dirs 'libs'
//        }
//
//    }

}
dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile(name: 'maputil-release', ext: 'aar')
    compile(name: 'commonreportpage', ext: 'aar')
    compile(name: 'compass-release', ext: 'aar')
    compile(name: 'towerheightmeter-release', ext: 'aar')
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'org.greenrobot:greendao:2.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.github.stfalcon:frescoimageviewer:0.4.1'
    compile 'com.facebook.fresco:fresco:1.1.0'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.commit451:PhotoView:1.2.4'
    compile 'com.isseiaoki:simplecropview:1.0.13'
    compile 'com.yongchun:com.yongchun.imageselector:1.1.0'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.0.7'
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

//    compile 'com.android.support:multidex:1.0.1'
}

//apply plugin: 'me.tatarka.retrolambda'

完整proguard-rules.pro
proguard-rules.pro中实体类model要避免混淆

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in W:\AndroidSDKNew/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-keep class !com.jsptpd.** {*;}
-keep class com.jsptpd.srfa.model.** {*;}
-keep class com.jsptpd.workformcommon.Model.** {*;}
-keep class com.jsptpd.srfa.restapi.ResponseObj {*;}
-keep class com.jsptpd.srfa.restapi.Error {*;}
-keep class com.jsptpd.srfa.view.widget.LayerControl.Model.** {*;}  #图层功能混淆


-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}
-keepattributes Signature
-keepattributes Exceptions


-keepclassmembers class * extends de.greenrobot.dao.AbstractDao {
     public static java.lang.String TABLENAME;
 }
 -keep class **$Properties



-dontwarn com.pgyersdk.**
-keep class com.pgyersdk.** { *; }

-dontwarn **

# Retrofit
-keep class retrofit2.** { *; }
-dontwarn retrofit2.**
-keepattributes Signature
-keepattributes Exceptions
-dontwarn okio.**
-dontwarn javax.annotation.**

# RxJava RxAndroid
-dontwarn sun.misc.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
    long producerIndex;
    long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
-dontnote rx.internal.util.PlatformDependent

见项目智慧查勘/通用查勘 E:\ASProject\newapp引入了下面两个项目的aar
E:\ASProject\010trunk\CommonReportPage
E:\ASProject\010trunk\maputil

相关文章

网友评论

      本文标题:android打包aar、发布签名包、混淆

      本文链接:https://www.haomeiwen.com/subject/whhvoftx.html