안녕하세요 키워드로 장소검색 api에 관련해서 문의드립니다
private fun searchKeyword(keyword: String) {
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
val api = retrofit.create(KakaoAPI::class.java)
val call = api.getSearchKeyword(API_KEY, keyword)
call.enqueue(object: Callback<ResultSearchKeyword> {
override fun onResponse(call: Call<ResultSearchKeyword>, response: Response<ResultSearchKeyword>) {
if (response.isSuccessful) {
val result = response.body()
if (result != null) {
val documents = result.documents
if (documents.isNotEmpty()) {
Log.e("edit search", response.message().toString())
Log.e("edit search", response.code().toString())
Log.e("edit search", documents.toString())
addItemsAndMarkers(result)
} else {
Log.e("edit search", "No documents found")
}
} else {
Log.e("edit search", "Response body is null")
}
} else {
Log.e("EDIT Search", response.code().toString())
Log.e("EDIT Search", response.errorBody().toString())
Log.e("EDIT Search", response.errorBody()?.string() ?: "Unknown error")
Log.e("EDIT Search", call.request().toString())
Log.e("EDIT Search", response.message().toString())
}
}
override fun onFailure(call: Call<ResultSearchKeyword>, t: Throwable) {
Log.w("LocalSearch", "통신 실패: ${t.message}")
}
})
}
(https://jangstory.tistory.com/43) 이 분 블로그와 같이 코드를 구현하여 키워드로 장소검색을 해보려했는데
200코드는 받아오는데 document값으로는 아무것도 받아오지 못해 null을 출력합니다
이 현상이 결국 proguard와 연관있음을 확인하고 dev talk, 구글링, github 등 찾아봐서 있을 만한거 다 넣어도
minifyEnabled true일때는 null이고 minifyEnabled false일 때는 잘 받아오더군요… 혹시 proguard를 어떤 식으로 설정해야할까요?
//현재 proguard
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
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
Keep annotation default values (e.g., retrofit2.http.Field.encoded).
-keepattributes AnnotationDefault
Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName ;
}
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.* ; }
-keep,allowobfuscation interface <1>
Keep inherited services.
-if interface * { @retrofit2.http.* ; }
-keep,allowobfuscation interface * extends <1>
With R8 full mode generic signatures are stripped for classes that are not
kept. Suspend functions are wrapped in continuations where the type argument
is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
R8 full mode strips generic signatures from return types if not kept.
-if interface * { @retrofit2.http.* public *** *(…); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
With R8 full mode generic signatures are stripped for classes that are not kept.
-keep,allowobfuscation,allowshrinking class retrofit2.Response
Retrofit and OkHttp
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
Retrofit
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
Gson
-keep class com.google.gson.** { ; }
-keep class com.google.gson.stream.* { *; }
-keepattributes Annotation
-keepattributes Signature
-keepattributes Annotation
Models
-keep class your.package.name.model.** { *; }
Kakao Map SDK
-keep class com.kakao.** { ; }
-keep class net.daum.mf.map.api.* { ; }
-dontwarn net.daum.mf.map.api.*
-dontwarn net.daum.android.**
-dontwarn com.kakao.**
-keep class net.daum.android.map.location.MapViewLocationManager { ; }
-keep class net.daum.* {;}
-keep class android.opengl.** {;}
-keep class com.kakao.util.maps.helper.** {*;}
-keepattributes Signature
-keepclassmembers class * {
public static ;
public *;
}