Skip to content

Commit

Permalink
fix Obfuscation for dagget hilt
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaConz committed Jul 16, 2024
1 parent f98ea09 commit 82d1280
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 82 deletions.
15 changes: 12 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ android {
versionCode = 1
versionName = "1.0"

multiDexEnabled = true

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

}

buildTypes {
debug {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
release {
isMinifyEnabled = false
proguardFiles(
Expand All @@ -33,11 +42,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "17"
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
Expand Down
37 changes: 0 additions & 37 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

##---------------Begin: proguard configuration for GLIDE ----------

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
<init>(...);
}
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
*** rewind();
}

##---------------End: proguard configuration for GLIDE ----------
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
Expand All @@ -7,4 +8,10 @@ plugins {
alias(libs.plugins.parcelize) apply false
alias(libs.plugins.android.dynamic.feature) apply false
alias(libs.plugins.android.library) apply false
}

buildscript {
dependencies {
classpath(libs.hilt.android.gradle.plugin)
}
}
18 changes: 14 additions & 4 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,27 @@ android {
}

buildTypes {
debug {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
release {
isMinifyEnabled = false
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "17"
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
Expand All @@ -61,4 +68,7 @@ dependencies{

implementation(libs.androidx.sqlite)
implementation(libs.sqlchiper)

implementation(libs.hilt.android)
ksp(libs.hilt.compiler)
}
171 changes: 169 additions & 2 deletions core/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -1,16 +1,183 @@
##---------------Begin: proguard configuration for SQLCipher ----------
-keep,includedescriptorclasses class net.sqlcipher.** { *; }
-keep,includedescriptorclasses interface net.sqlcipher.** { *; }


##---------------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>;
@com.google.gson.annotations.SerializedName <fields>;
}


##---------------Begin: proguard configuration for Retrofit ----------
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod

# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**

# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*

# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>

-dontwarn kotlinx.**


##---------------Begin: proguard configuration for Glide ----------
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
<init>(...);
}
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
*** rewind();
}

# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-dontwarn org.conscrypt.ConscryptHostnameVerifier

-dontwarn com.airbnb.lottie.**
-keep class com.airbnb.lottie.** {*;}

#-------------------------------------------------
# JetPack Navigation
# This fixes: Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists
#-------------------------------------------------
-keepnames class androidx.navigation.fragment.NavHostFragment

-dontwarn com.sun.javadoc.Doclet

-dontwarn java.lang.invoke.StringConcatFactory

-keep class java.lang.invoke.** {*;}

# Keep MovieRepository and its members
-keep class com.example.core.data.MovieRepository { *; }
-keep class com.example.core.** { *; }

# Keep Resource classes and their members
-keep class com.example.core.data.Resource$Error { *; }
-keep class com.example.core.data.Resource$Loading { *; }
-keep class com.example.core.data.Resource$Success { *; }
-keep class com.example.core.data.Resource { *; }

# Keep DataSource classes and their members
-keep class com.example.core.data.source.local.LocalDataSource { *; }
-keep class com.example.core.data.source.remote.RemoteDataSource { *; }
-keep class com.example.core.data.source.remote.net.ApiService { *; }

# Keep DI modules and their providers
-keep class com.example.core.di.** { *; }
-keep class com.example.core.di.DatabaseModule { *; }
-keep class com.example.core.di.DatabaseModule_ProvideDatabaseFactory { *; }
-keep class com.example.core.di.DatabaseModule_ProvideMovieDaoFactory { *; }
-keep class com.example.core.di.NetworkModule { *; }
-keep class com.example.core.di.NetworkModule_ProvideApiServiceFactory { *; }
-keep class com.example.core.di.NetworkModule_ProvideOkHttpClientFactory { *; }

# Keep domain classes and their members
-keep class com.example.core.domain.model.Movie { *; }
-keep class com.example.core.domain.repository.IMovieRepository { *; }
-keep class com.example.core.domain.usecase.MovieInteractor { *; }
-keep class com.example.core.domain.usecase.MovieUseCase { *; }

# Keep UI classes and their members
-keep class com.example.core.ui.MovieAdapter { *; }

# Keep utility classes
-keep class com.example.core.utils.AppExecutors { *; }

-keep class com.example.core.di.DatabaseModule { *; }

-keep com.example.core.di.**

-keepnames com.example.core.di.**

# Keep Hilt components
-keep class * implements dagger.hilt.internal.GeneratedComponent { *; }
-keep class * implements dagger.hilt.internal.GeneratedComponentManager { *; }
-keep class * implements dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper { *; }

# Keep classes with @Inject constructors
-keepclasseswithmembernames class * {
@javax.inject.Inject <init>(...);
}

# Keep Hilt Android classes (for projects using Hilt with Android)
-keep class dagger.hilt.android.** { *; }
-keep interface dagger.hilt.android.** { *; }

# Keep classes annotated with @HiltAndroidApp, @AndroidEntryPoint, etc.
-keep @dagger.hilt.android.HiltAndroidApp class *
-keep @dagger.hilt.android.AndroidEntryPoint class *
-keep @dagger.hilt.InstallIn class *
-keep @dagger.Module class *
-keep @dagger.hilt.components.SingletonComponent class *
-keep @dagger.hilt.android.components.ActivityComponent class *
-keep @dagger.hilt.android.components.FragmentComponent class *

# Keep classes with @Module annotations
-keep @dagger.Module class * { *; }

# Keep classes with @Provides annotations
-keep class * {
@dagger.Provides <methods>;
}

-keep class com.example.core.domain.model.** { *; }
# Keep annotations
-keepattributes *Annotation*
21 changes: 0 additions & 21 deletions core/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class LocalDataSource @Inject constructor(private val movieDao: MovieDao) {

fun searchMovie(value: String): Flow<List<MovieEntity>> = movieDao.searchMovies(value)

fun getAllTvShows(): Flow<List<MovieEntity>> = movieDao.getListTvShows()

fun getFavoriteTvShows(): Flow<List<MovieEntity>> = movieDao.getBookmarkedTvShows()

fun searchTvShows(value: String): Flow<List<MovieEntity>> = movieDao.searchTvShows(value)

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ interface MovieDao {
@Query("SELECT * FROM movie WHERE title LIKE '%' || :search || '%' and isTvShows = 0")
fun searchMovies(search: String): Flow<List<MovieEntity>>


@Query("SELECT * FROM movie where isTvShows = 1 ")
fun getListTvShows(): Flow<List<MovieEntity>>

@Query("SELECT * FROM movie where bookmarked = 1 and isTvShows = 1")
fun getBookmarkedTvShows(): Flow<List<MovieEntity>>

@Query("SELECT * FROM movie WHERE title LIKE '%' || :search || '%' and isTvShows = 1")
fun searchTvShows(search: String): Flow<List<MovieEntity>>
}
1 change: 0 additions & 1 deletion core/src/main/java/com/example/core/di/DatabaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class DatabaseModule {
.openHelperFactory(factory)
.build()
}

@Provides
fun provideMovieDao(database: MovieDatabase): MovieDao = database.movieDao()
}
6 changes: 3 additions & 3 deletions favorite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "17"
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
Expand Down
Loading

0 comments on commit 82d1280

Please sign in to comment.