即使使用 -keep class 仍然出现错误 Unresolved reference
still got error Unresolved reference even with the -keep class
在项目中它有一个 class in OptionalDependencies.kt
package com.xyz.demo
import android.content.Context
import com.facebook.stetho.Stetho
import com.facebook.stetho.okhttp3.StethoInterceptor
import okhttp3.Interceptor
object OptionalDependencies {
fun initStetho(context: Context) {
Stetho.initializeWithDefaults(context)
}
fun getNetworkInterceptor() : Interceptor? = StethoInterceptor()
}
并在 StartActivity.kt
package com.xyz.demo.ui
import com.xyz.demo.OptionalDependencies
……
class StartActivity : AppCompatActivity() {
private fun initStetho(@ApplicationContext appContext: Context) {
val interceptor : Interceptor? =
OptionalDependencies.getNetworkInterceptor()//<=== any where will get error referring the
……
}
……
}
在build.gradle
buildTypes {
debug {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
在proguard-rules.pro
-keep class com.xyz.demo.** {*;}
也试过-keep class com.xyz.demo.OptionalDependencies {*;}
得到错误:
e:/Users/sample/src/main/java/com/xyz/demo/ui/StartActivity.kt:
(527, 42): Unresolved reference: OptionalDependencies
如果关闭 proguard 它工作正常。
我想在对 proguard-rules.pro
进行更改后必须做一个 "sync",然后重新构建。
在项目中它有一个 class in OptionalDependencies.kt
package com.xyz.demo
import android.content.Context
import com.facebook.stetho.Stetho
import com.facebook.stetho.okhttp3.StethoInterceptor
import okhttp3.Interceptor
object OptionalDependencies {
fun initStetho(context: Context) {
Stetho.initializeWithDefaults(context)
}
fun getNetworkInterceptor() : Interceptor? = StethoInterceptor()
}
并在 StartActivity.kt
package com.xyz.demo.ui
import com.xyz.demo.OptionalDependencies
……
class StartActivity : AppCompatActivity() {
private fun initStetho(@ApplicationContext appContext: Context) {
val interceptor : Interceptor? =
OptionalDependencies.getNetworkInterceptor()//<=== any where will get error referring the
……
}
……
}
在build.gradle
buildTypes {
debug {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
在proguard-rules.pro
-keep class com.xyz.demo.** {*;}
也试过-keep class com.xyz.demo.OptionalDependencies {*;}
得到错误:
e:/Users/sample/src/main/java/com/xyz/demo/ui/StartActivity.kt:
(527, 42): Unresolved reference: OptionalDependencies
如果关闭 proguard 它工作正常。
我想在对 proguard-rules.pro
进行更改后必须做一个 "sync",然后重新构建。