Android编程之快速创建项目

Android编程之快速创建项目

你好! 这是我的安卓学习日记,希望对你有帮助!

settings.gradle配置

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        maven { url "https://maven.aliyun.com/repository/public/" }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        maven { url "https://maven.aliyun.com/repository/public/" }
    }
}
rootProject.name = "XjSkills"
include ':app'

生成jks(签名)文件

Build ☞ Generate signed bundle/Apk ☞ Apk ☞ Next ☞ Create new… ☞ 选择项目跟目录 ☞ 填写其他信息 ☞ Next ☞ Cancel 。然后关闭窗口即可。(无需点击Finish,点击会开始生成Apk)

app/build.gradle配置

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

// 定义应用名称
def appName = "SmartCity"

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.xjskills.app"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0.0"
        resConfigs "zh", "en"
        ndk {
            //设置支持的SO库架构(开发者可以根据需要,选择一个或多个平台的so)
            abiFilters /*"armeabi", */ "armeabi-v7a", "arm64-v8a"/*, "x86", "x86_64"*/
        }

        manifestPlaceholders = [XjSkills: "XjSkills"]
        buildConfigField("String", "HOST", "\"http://smartcity.lenovoedu.com/interface/\"")
    }

    applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${appName}-${variant.buildType.name}.apk"
        }
    }

    signingConfigs {
        debug {
            storeFile file('../XjSkills.jks')
            storePassword 'XjSkills'
            keyAlias 'XjSkills'
            keyPassword 'XjSkills'
        }
        release {
            storeFile file('../XjSkills.jks')
            storePassword 'XjSkills'
            keyAlias 'XjSkills'
            keyPassword 'XjSkills'
        }
    }

    buildTypes {
        debug {
            debuggable true
            //打开混淆
            minifyEnabled false
            //打开资源压缩
            shrinkResources false
            signingConfig signingConfigs.debug
        }
        release {
            debuggable false
            //打开混淆
            minifyEnabled true
            //打开资源压缩
            shrinkResources true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    buildFeatures {
        viewBinding true
    }
}

dependencies {
    implementation project(path: ':arch')
    implementation project(path: ':widget')
    //Development
    debugImplementation files('libs/SQLiteStudioRemote.jar')
    debugImplementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'

    //rxjava
    implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
    implementation 'io.reactivex.rxjava3:rxjava:3.1.5'

    //retrofit + gson
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'

    //LoadSir 状态显示
    implementation 'com.kingja.loadsir:loadsir:1.3.8'
    implementation 'com.wang.avi:library:2.1.3'

    //New features
//    implementation 'com.github.AppIntro:AppIntro:6.2.0'
    //ViewPagerIndicator
//    implementation 'com.github.LinweiJ:ViewPagerIndicator:0.3.0'
    //ViewPager2Indicator
//    implementation 'com.tbuonomo:dotsindicator:4.2'
}

混淆文件配置

在app目录下新建一个混淆配置文件:gson-proguard-rules.pro

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
# -keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

##---------------End: proguard configuration for Gson  ----------

然后在 proguardFiles 后面配置gson-proguard-rules.pro

配置已完成

现在我们可以愉快的开发项目啦!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

a.erke

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值