Skip to content

Commit

Permalink
setting: AGP 8.0.2 & 카카오 리다이렉션 해결 ㅠㅜㅠ
Browse files Browse the repository at this point in the history
  • Loading branch information
HI-JIN2 committed Oct 28, 2023
1 parent e8d42cc commit 8b9a316
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 103 deletions.
34 changes: 11 additions & 23 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,25 @@ plugins {

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def BASE_URL = properties.getProperty('BASE_URL')
def KAKAO_NATIVE_APP_KEY = properties.getProperty('KAKAO_NATIVE_APP_KEY')
def KAKAO_REDIRECTION_SCHEME = properties.getProperty('KAKAO_REDIRECTION_SCHEME')



android {
namespace 'com.eatssu.android'
compileSdk 33
// compileSdkVersion 33 // 원하는 SDK 버전으로 변경하세요
compileSdk 34

defaultConfig {
applicationId "com.eatssu.android"
minSdk 21
compileSdkVersion 33
targetSdk 33
compileSdkVersion 34
targetSdk 34
versionCode 1
versionName "1.0"


buildConfigField "String", "BASE_URL", properties["BASE_URL"]

buildConfigField("String", "BASE_URL", BASE_URL)
manifestPlaceholders = [BASE_URL: BASE_URL]

buildConfigField("String", "KAKAO_NATIVE_APP_KEY", KAKAO_NATIVE_APP_KEY)
manifestPlaceholders = [KAKAO_NATIVE_APP_KEY: KAKAO_NATIVE_APP_KEY]

buildConfigField("String", "KAKAO_REDIRECTION_SCHEME", KAKAO_REDIRECTION_SCHEME)
manifestPlaceholders = [KAKAO_REDIRECTION_SCHEME: KAKAO_REDIRECTION_SCHEME]
buildConfigField("String", "KAKAO_NATIVE_APP_KEY", "\"${properties.get('KAKAO_NATIVE_APP_KEY')}\"")
manifestPlaceholders = [KAKAO_NATIVE_APP_KEY: properties.get('KAKAO_NATIVE_APP_KEY')]

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -108,10 +98,8 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'

// implementation group: 'com.kakao.sdk', name: 'usermgmt', version: '1.30.0'
// implementation group: 'com.kakao.sdk', name: 'kakaolink', version: '1.30.5'

implementation "com.kakao.sdk:v2-user:2.5.0" // 카카오 로그인
// 카카오 로그인 모듈
implementation "com.kakao.sdk:v2-user:2.8.6" // 카카오 로그인

implementation 'com.google.dagger:hilt-android:2.47'
annotationProcessor 'com.google.dagger:hilt-compiler:2.47'
Expand All @@ -120,12 +108,12 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.1"

implementation 'androidx.activity:activity-ktx:1.1.0'
implementation 'androidx.fragment:fragment-ktx:1.2.5'
implementation 'androidx.activity:activity-ktx:1.8.0'
implementation 'androidx.fragment:fragment-ktx:1.6.1'

// implementation "androidx.security:security-crypto:1.0.0"

implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'com.github.bumptech.glide:glide:4.15.1'
// kapt 'com.github.bumptech.glide:compiler:4.12.0'

implementation 'id.zelory:compressor:3.0.1'
Expand Down
18 changes: 7 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@
android:value="" />
</activity>

<meta-data
android:name="com.kakao.sdk.AppKey"
android:value="$kakao_native_app_key" /> <!-- <meta-data -->
<!-- android:name="com.kakao.sdk.AppKey" -->
<!-- android:value="${APP_KEY}" /> -->


<activity
android:name=".view.main.ForceUpdateDialogActivity"
Expand All @@ -74,21 +70,21 @@
android:name="android.app.lib_name"
android:value="" />
</activity>
<!-- <meta-data-->
<!-- android:name="com.kakao.sdk.AppKey"-->
<!-- android:value="$KAKAO_NATIVE_APP_KEY" />-->

<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true"
android:launchMode="singleTask">
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- Redirect URI: "kakao{NATIVE_APP_KEY}://oauth" -->
<data
android:host="oauth"
android:scheme="${KAKAO_REDIRECTION_SCHEME}" />
</intent-filter>
android:scheme="kakao${KAKAO_NATIVE_APP_KEY}" /> </intent-filter>
</activity>
<activity
android:name=".base.BaseActivity"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/eatssu/android/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class App: Application() {

token_prefs = TokenSharedPreferences(applicationContext)

val apiKey = BuildConfig.KAKAO_NATIVE_APP_KEY
// val apiKey = BuildConfig.KAKAO_NATIVE_APP_KEY

appContext = this
KakaoSdk.init(this,BuildConfig.KAKAO_NATIVE_APP_KEY)
Expand Down
193 changes: 131 additions & 62 deletions app/src/main/java/com/eatssu/android/view/login/SocialLoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.eatssu.android.view.login
import android.content.ContentValues.TAG
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.webkit.WebView
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.eatssu.android.App
Expand All @@ -17,6 +19,7 @@ import com.eatssu.android.data.model.response.TokenResponseDto
import com.eatssu.android.data.service.OauthService
import com.eatssu.android.databinding.ActivitySocialLoginBinding
import com.eatssu.android.view.main.MainActivity
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
import com.kakao.sdk.user.UserApiClient
Expand All @@ -29,62 +32,21 @@ import java.net.URISyntaxException

class SocialLoginActivity : AppCompatActivity() {
private lateinit var binding: ActivitySocialLoginBinding
val KAKAOTAG = "카카오소셜로그인"

// 코틀린
fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
if (url != null && url.startsWith("intent://")) {
try {
val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
val existPackage =
packageManager.getLaunchIntentForPackage(intent.getPackage()!!)
if (existPackage != null) {
startActivity(intent)
} else {
val marketIntent = Intent(Intent.ACTION_VIEW)
marketIntent.data =
Uri.parse("market://details?id=" + intent.getPackage()!!)
startActivity(marketIntent)
}
return true
} catch (e: Exception) {
e.printStackTrace()
}
var userEmail: String? = null

} else if (url != null && url.startsWith("market://")) {
try {
val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
if (intent != null) {
startActivity(intent)
}
return true
} catch (e: URISyntaxException) {
e.printStackTrace()
}

}
view.loadUrl(url)
return false
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySocialLoginBinding.inflate(layoutInflater)
setContentView(binding.root)

//카카오 로그인에서 제공하는 자동로그인 메소드
// UserApiClient.instance.accessTokenInfo { tokenInfo, error ->
// if (error != null) {
// Toast.makeText(this, "자동 로그인 실패", Toast.LENGTH_SHORT).show()
// }
// else if (tokenInfo != null) {
// Toast.makeText(this, "자동 로그인 성공", Toast.LENGTH_SHORT).show()
// val intent = Intent(this, MainActivity::class.java)
// startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
// }
// }

// SharedPreferences 안에 값이 저장되어 있을 때-> Login 패스하기
if (MySharedPreferences.getUserEmail(this).isNotBlank()){// SharedPreferences 안에 값이 저장되어 있을 때 -> MainActivity로 이동
if (MySharedPreferences.getUserEmail(this).isNotBlank()) {
// SharedPreferences 안에 값이 저장되어 있을 때 -> MainActivity로 이동
Toast.makeText(
this,
"자동 로그인 되었습니다.",
Expand All @@ -97,31 +59,138 @@ class SocialLoginActivity : AppCompatActivity() {

val context = this


binding.imbKakao.setOnClickListener {
lifecycleScope.launch {
try {
// 서비스 코드에서는 간단하게 로그인 요청하고 oAuthToken 을 받아올 수 있다.
val oAuthToken = UserApiClient.loginWithKakao(context)
Log.d("MainActivity", "beanbean > $oAuthToken")
postUserInfo();

} catch (error: Throwable) {

Log.d("post", "버튼 클릭")
kakaoSignIn()
// lifecycleScope.launch {
// try {
// // 서비스 코드에서는 간단하게 로그인 요청하고 oAuthToken 을 받아올 수 있다.
// val oAuthToken = UserApiClient.loginWithKakao(context)
// Log.d("MainActivity", "beanbean > $oAuthToken")
// postUserInfo();
//
// } catch (error: Throwable) {
// if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
// Log.d("MainActivity", "사용자가 명시적으로 취소")
// } else {
// Log.e("MainActivity", "인증 에러 발생", error)
// }
// }
// }
// }
}
}

private fun kakaoSignIn() { // 카카오 소셜로그인
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
if (error != null) {
Log.d(KAKAOTAG, "카카오계정으로 로그인 실패", error)
} else if (token != null) {
Log.d(KAKAOTAG, "카카오계정으로 로그인 성공 ${token.accessToken}")
kakaoInfo()
}
}

if (UserApiClient.instance.isKakaoTalkLoginAvailable(this)) {
UserApiClient.instance.loginWithKakaoTalk(this) { token, error ->
if (error != null) {
Log.d(KAKAOTAG, "카카오톡으로 로그인 실패", error)
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
Log.d("MainActivity", "사용자가 명시적으로 취소")
} else {
Log.e("MainActivity", "인증 에러 발생", error)
return@loginWithKakaoTalk
}
// 카카오톡에 연결된 카카오계정이 없는 경우, 카카오계정으로 로그인 시도
UserApiClient.instance.loginWithKakaoAccount(this@SocialLoginActivity, callback = callback)
} else if (token != null) {
Log.i(KAKAOTAG, "카카오톡으로 로그인 성공 ${token.accessToken}")
kakaoInfo()
}
}
} else {
UserApiClient.instance.loginWithKakaoAccount(this@SocialLoginActivity, callback = callback)
}
//둘러보기 MVP에서 제외
// binding.btnLookAround.setOnClickListener() {
// val intent = Intent(this, MainActivity::class.java) // 인텐트를 생성해줌,
// startActivity(intent) // 화면 전환을 시켜줌
// finish()
// }
}

fun kakaoInfo() {
UserApiClient.instance.me { user, error ->
if (error != null) {
Log.d(KAKAOTAG, "사용자 정보 요청 실패", error)
} else if (user != null) {
userEmail = user.kakaoAccount?.email
Log.d("kakao","info")
// socialSignInApi(userEmail!!,"KAKAO")
// Toast.makeText(this@SignIn, "email : $userEmail pw : $userPw", Toast.LENGTH_LONG).show()
}
}
}

// private fun socialSignInApi(userEmail: String, userPw: String, platform: String) {
// val service = nonRetrofit.create(OauthService::class.java)
//
// val LoginInfo = LoginRequest(userEmail, userPw)
// service.oauthLogIn(LoginInfo).enqueue(object : Callback<BaseResponse<TokenResponse>> {
//
// @RequiresApi(Build.VERSION_CODES.O)
// override fun onResponse(
// call: Call<BaseResponse<TokenResponse>>,
// response: Response<BaseResponse<TokenResponse>>,
// ) {
// val code = response.body()?.code
//
// if (response.isSuccessful) {
// if (code == 200) {
// // val mIntent = Intent(this@SignIn, BottomNavi::class.java)
// Log.d("SignInDebug", "소셜 로그인 성공~ : " + response.headers().toString())
//
// // 자동로그인
// UserSharedPreferences.setUserEmail(this@SignInActivity, userEmail)
// UserSharedPreferences.setUserPw(this@SignInActivity, userPw)
// //
//
// // 토큰저장
// App.token_prefs.accessToken = response.body()!!.result?.accessToken
// App.token_prefs.refreshToken = response.body()!!.result?.refreshToken
//
// Log.d("로그인 sh 확인 로그 이메일", UserSharedPreferences.getUserEmail(this@SignInActivity))
// Log.d("로그인 sh 확인 로그 비번", UserSharedPreferences.getUserPw(this@SignInActivity))
// Log.d("로그인 sh 확인 로그 서버에서 온 액세스 토큰", App.token_prefs.accessToken.toString())
// Log.d("로그인 sh 확인 로그 서버에서 온 리프래시 토큰", App.token_prefs.refreshToken.toString())
// Log.d("로그인 sh 확인 로그 액세스 토큰", App.token_prefs.accessToken.toString())
// Log.d("로그인 sh 확인 로그 리프래시 토큰", App.token_prefs.refreshToken.toString())
//
// moveToHome()
// // startActivity(mIntent)
// } else {
// Log.d(
// "SignInDebug",
// "아이디 비번 틀림",
// )
// customSingInPopupWindow(
// this@SignInActivity,
// ALERT_TEXT_SIGN_IN,
// binding.root,
// binding.btnSigninSignin,
// )
// }
// } else {
// Log.d(
// "SignInDebug",
// "소셜로그인, 정보 존재하지 않음. 회원가입 필요한경우임 ${response?.toString()}",
// )
// val mIntent = Intent(this@SignInActivity, NicknameActivity::class.java)
// mIntent.putExtra("email", userEmail)
// mIntent.putExtra("password", userPw)
// mIntent.putExtra("platform", platform)
// startActivity(mIntent)
// }
// }
//
// override fun onFailure(call: Call<BaseResponse<TokenResponse>>, t: Throwable) {
// Log.d("SignInDebug", "onFailure 에러: " + t.message.toString())
// }
// })
// }
private fun postUserInfo() {
UserApiClient.instance.me { user, error ->
if (user != null) {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
id 'com.google.gms.google-services' version "4.3.15" apply false
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ kotlin.code.style=official
# 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
android.enableJetifier=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Feb 17 11:26:14 KST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Loading

0 comments on commit 8b9a316

Please sign in to comment.