From 2e107e7356c604df51b62eba9a98b2df6109a994 Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Mon, 23 May 2022 23:45:37 +0800 Subject: [PATCH] update gradle to new format turn on nonTransitiveRClass --- app/build.gradle | 22 ++++++---- app/src/main/AndroidManifest.xml | 3 +- .../java/io/legado/app/constant/AppConst.kt | 5 ++- .../legado/app/lib/prefs/ColorPreference.kt | 2 +- .../legado/app/lib/prefs/SwitchPreference.kt | 2 +- .../app/lib/theme/MaterialValueHelper.kt | 36 ++++++++++++----- .../io/legado/app/lib/theme/ThemeStore.kt | 15 +++++-- .../io/legado/app/lib/theme/TintHelper.kt | 6 +-- .../legado/app/ui/widget/image/PhotoView.kt | 3 +- build.gradle | 40 ++++++------------- epublib/build.gradle | 12 +++--- gradle.properties | 7 +++- gradle/wrapper/gradle-wrapper.properties | 4 +- settings.gradle | 30 ++++++++++++++ 14 files changed, 119 insertions(+), 68 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7820fa23c..27e1c868c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,9 +1,11 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-parcelize' -apply plugin: 'kotlin-kapt' -apply plugin: 'de.timfreiheit.resourceplaceholders' -apply plugin: 'com.google.gms.google-services' +plugins { + id "com.android.application" + id 'org.jetbrains.kotlin.android' + id 'kotlin-parcelize' + id 'kotlin-kapt' + id "de.timfreiheit.resourceplaceholders" + id "com.google.gms.google-services" +} apply from: 'download.gradle' static def releaseTime() { @@ -16,11 +18,15 @@ def gitCommits = Integer.parseInt('git rev-list HEAD --count'.execute().text.tri android { compileSdkVersion 32 - buildToolsVersion '32.0.0' + buildToolsVersion "32.0.0" + namespace 'io.legado.app' kotlinOptions { jvmTarget = "11" } - namespace 'io.legado.app' + lintOptions{ + checkDependencies true + } + signingConfigs { if (project.hasProperty("RELEASE_STORE_FILE")) { myConfig { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2275e93eb..fed8456c5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index 7de237e42..49220b429 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -5,7 +5,6 @@ import android.content.pm.PackageManager import android.provider.Settings import com.script.javascript.RhinoScriptEngine import io.legado.app.BuildConfig -import io.legado.app.R import splitties.init.appCtx import java.text.SimpleDateFormat @@ -57,7 +56,9 @@ object AppConst { ) @SuppressLint("PrivateResource") - val sysElevation = appCtx.resources.getDimension(R.dimen.design_appbar_elevation).toInt() + val sysElevation = + appCtx.resources.getDimension(com.google.android.material.R.dimen.design_appbar_elevation) + .toInt() val androidId: String by lazy { Settings.System.getString(appCtx.contentResolver, Settings.Secure.ANDROID_ID) ?: "null" diff --git a/app/src/main/java/io/legado/app/lib/prefs/ColorPreference.kt b/app/src/main/java/io/legado/app/lib/prefs/ColorPreference.kt index 3ea1181a1..b427992e7 100644 --- a/app/src/main/java/io/legado/app/lib/prefs/ColorPreference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/ColorPreference.kt @@ -120,7 +120,7 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex override fun onBindViewHolder(holder: PreferenceViewHolder) { val v = io.legado.app.lib.prefs.Preference.bindView( context, holder, icon, title, summary, widgetLayoutResource, - io.legado.app.R.id.cpv_preference_preview_color_panel, 30, 30 + com.jaredrummler.android.colorpicker.R.id.cpv_preference_preview_color_panel, 30, 30 ) if (v is ColorPanelView) { v.color = mColor diff --git a/app/src/main/java/io/legado/app/lib/prefs/SwitchPreference.kt b/app/src/main/java/io/legado/app/lib/prefs/SwitchPreference.kt index d71e914b7..1671b73fc 100644 --- a/app/src/main/java/io/legado/app/lib/prefs/SwitchPreference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/SwitchPreference.kt @@ -30,7 +30,7 @@ class SwitchPreference(context: Context, attrs: AttributeSet) : title, summary, widgetLayoutResource, - R.id.switchWidget, + androidx.preference.R.id.switchWidget, isBottomBackground = isBottomBackground ) if (v is SwitchCompat && !v.isInEditMode) { diff --git a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt index d19b6634c..550c3092f 100644 --- a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt @@ -19,34 +19,52 @@ import io.legado.app.utils.dpToPx @ColorInt fun Context.getPrimaryTextColor(dark: Boolean): Int { return if (dark) { - ContextCompat.getColor(this, R.color.primary_text_default_material_light) - } else ContextCompat.getColor(this, R.color.primary_text_default_material_dark) + ContextCompat.getColor(this, androidx.appcompat.R.color.primary_text_default_material_light) + } else ContextCompat.getColor( + this, + androidx.appcompat.R.color.primary_text_default_material_dark + ) } @ColorInt fun Context.getSecondaryTextColor(dark: Boolean): Int { return if (dark) { - ContextCompat.getColor(this, R.color.secondary_text_default_material_light) + ContextCompat.getColor( + this, + androidx.appcompat.R.color.secondary_text_default_material_light + ) } else { - ContextCompat.getColor(this, R.color.secondary_text_default_material_dark) + ContextCompat.getColor( + this, + androidx.appcompat.R.color.secondary_text_default_material_dark + ) } } @ColorInt fun Context.getPrimaryDisabledTextColor(dark: Boolean): Int { return if (dark) { - ContextCompat.getColor(this, R.color.primary_text_disabled_material_light) + ContextCompat.getColor( + this, + androidx.appcompat.R.color.primary_text_disabled_material_light + ) } else { - ContextCompat.getColor(this, R.color.primary_text_disabled_material_dark) + ContextCompat.getColor(this, androidx.appcompat.R.color.primary_text_disabled_material_dark) } } @ColorInt fun Context.getSecondaryDisabledTextColor(dark: Boolean): Int { return if (dark) { - ContextCompat.getColor(this, R.color.secondary_text_disabled_material_light) + ContextCompat.getColor( + this, + androidx.appcompat.R.color.secondary_text_disabled_material_light + ) } else { - ContextCompat.getColor(this, R.color.secondary_text_disabled_material_dark) + ContextCompat.getColor( + this, + androidx.appcompat.R.color.secondary_text_disabled_material_dark + ) } } @@ -124,7 +142,7 @@ val Context.elevation: Float ThemeUtils.resolveFloat( this, android.R.attr.elevation, - resources.getDimension(R.dimen.design_appbar_elevation) + resources.getDimension(com.google.android.material.R.dimen.design_appbar_elevation) ) } else { AppConfig.elevation.toFloat().dpToPx() diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt index c791b1d1a..9c8602eb5 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt @@ -9,7 +9,6 @@ import androidx.annotation.CheckResult import androidx.annotation.ColorInt import androidx.annotation.ColorRes import androidx.core.content.ContextCompat -import io.legado.app.R import io.legado.app.utils.ColorUtils import splitties.init.appCtx @@ -189,7 +188,11 @@ private constructor(private val mContext: Context) : ThemeStoreInterface { fun primaryColor(context: Context = appCtx): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_PRIMARY_COLOR, - ThemeUtils.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64")) + ThemeUtils.resolveColor( + context, + androidx.appcompat.R.attr.colorPrimary, + Color.parseColor("#455A64") + ) ) } @@ -200,7 +203,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface { ThemeStorePrefKeys.KEY_PRIMARY_COLOR_DARK, ThemeUtils.resolveColor( context, - R.attr.colorPrimaryDark, + androidx.appcompat.R.attr.colorPrimaryDark, Color.parseColor("#37474F") ) ) @@ -211,7 +214,11 @@ private constructor(private val mContext: Context) : ThemeStoreInterface { fun accentColor(context: Context = appCtx): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_ACCENT_COLOR, - ThemeUtils.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")) + ThemeUtils.resolveColor( + context, + androidx.appcompat.R.attr.colorAccent, + Color.parseColor("#263238") + ) ) } diff --git a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt index d1bfd0231..e8cf40d12 100644 --- a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt @@ -31,9 +31,9 @@ object TintHelper { // Light ripple is actually translucent black, and vice versa return ContextCompat.getColor( context, if (useDarkRipple) - R.color.ripple_material_light + androidx.appcompat.R.color.ripple_material_light else - R.color.ripple_material_dark + androidx.appcompat.R.color.ripple_material_dark ) } @@ -170,7 +170,7 @@ object TintHelper { val rd = view.background as RippleDrawable @SuppressLint("PrivateResource") val unchecked = ContextCompat.getColor( view.context, - if (isDark) R.color.ripple_material_dark else R.color.ripple_material_light + if (isDark) androidx.appcompat.R.color.ripple_material_dark else androidx.appcompat.R.color.ripple_material_light ) val checked = ColorUtils.adjustAlpha(color, 0.4f) val sl = ColorStateList( diff --git a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt index b028dd116..7a67fef77 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt @@ -17,7 +17,6 @@ import android.widget.ImageView import android.widget.OverScroller import android.widget.Scroller import androidx.appcompat.widget.AppCompatImageView -import io.legado.app.R import io.legado.app.ui.widget.image.photo.Info import io.legado.app.ui.widget.image.photo.OnRotateListener import io.legado.app.ui.widget.image.photo.RotateGestureDetector @@ -917,7 +916,7 @@ class PhotoView @JvmOverloads constructor( var viewParent: ViewParent = target.parent while (viewParent is View) { val view: View = viewParent - if (view.id == R.id.content) return + if (view.id == androidx.constraintlayout.widget.R.id.content) return position[0] -= view.scrollX position[1] -= view.scrollY position[0] += view.left diff --git a/build.gradle b/build.gradle index 49eaac2b9..52a2f6b2e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,36 +1,22 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.6.10' - repositories { - //原仓库 - google() - mavenCentral() - maven { url 'https://plugins.gradle.org/m2/' } - //镜像仓库,无法连接源仓库自行启用镜像仓库,不要提交修改 - //maven { url 'https://maven.aliyun.com/repository/google' } - //maven { url 'https://maven.aliyun.com/repository/public' } - //maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } - } - dependencies { - classpath 'com.android.tools.build:gradle:7.2.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.4' - classpath 'de.undercouch:gradle-download-task:5.0.1' - classpath 'com.google.gms:google-services:4.3.10' + ext{ + kotlin_version = '1.6.10' + agp_version='7.2.0' } } -allprojects { - repositories { - //原仓库 - google() - mavenCentral() - maven { url 'https://jitpack.io' } - //镜像仓库,无法连接源仓库自行启用镜像仓库,不要提交修改 - //maven { url 'https://maven.aliyun.com/repository/google' } - //maven { url 'https://maven.aliyun.com/repository/public' } - } + + +plugins { + id 'com.android.application' version "$agp_version" apply false + id 'com.android.library' version "$agp_version" apply false + id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false + id "de.timfreiheit.resourceplaceholders" version "0.4" apply false + id "de.undercouch.download" version "5.1.0" apply false + id "com.google.gms.google-services" version "4.3.10" apply false + } task clean(type: Delete) { diff --git a/epublib/build.gradle b/epublib/build.gradle index 9fef4731a..9dbb6e226 100644 --- a/epublib/build.gradle +++ b/epublib/build.gradle @@ -3,12 +3,15 @@ plugins { } android { - compileSdkVersion 31 - buildToolsVersion '31.0.0' + compileSdkVersion 32 + buildToolsVersion '32.0.0' namespace 'me.ag2s.epublib' + lintOptions{ + checkDependencies true + } defaultConfig { minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 32 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" @@ -19,8 +22,7 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } - android { - } + } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/gradle.properties b/gradle.properties index ed228fa6e..07e4b9d60 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,8 +19,11 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official - android.enableResourceOptimizations=true - +android.enableNewResourceShrinker=true +android.experimental.enableNewResourceShrinker.preciseShrinking=true +# enables namespacing of each library's R class so that its R class includes only the resources declared in the library itself +# and none from the library's dependencies, thereby reducing the size of the R class for that library. +android.nonTransitiveRClass=true #https://chromiumdash.appspot.com/releases?platform=Android CronetVersion=101.0.4951.61 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 324b48f79..85c753bd8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri May 07 15:24:46 CST 2021 +#Mon May 23 22:07:39 CST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle index 6e5b9d8ee..fc8168e71 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,31 @@ +pluginManagement { + repositories { + //原仓库 + gradlePluginPortal() + google() + mavenCentral() + //镜像仓库,无法连接源仓库自行启用镜像仓库,不要提交修改 + //maven {url"https://maven-central-asia.storage-download.googleapis.com/maven2/"} + //maven { url 'https://maven.aliyun.com/repository/google' } + //maven { url 'https://maven.aliyun.com/repository/public' } + //maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + //原仓库 + google() + mavenCentral() + maven { url 'https://jitpack.io' } + //镜像仓库,无法连接源仓库自行启用镜像仓库,不要提交修改 + //maven {url"https://maven-central-asia.storage-download.googleapis.com/maven2/"} + //maven { url 'https://maven.aliyun.com/repository/google' } + //maven { url 'https://maven.aliyun.com/repository/public' } + + } +} +rootProject.name = 'legado' + include ':app',':epublib'