React-Native 카카오 안드로이드 모듈 만들기

puka·2022년 9월 13일

모듈 프로젝트 생성

react-native에서 제공하는 라이브러리를 이용합니다.

react-native-create-library
라는 리액트 네이티브 모듈을 만드는 템플릿이 있습니다. 터미널에서 다음과 같은 명령어를 입력합니다.

npx create-react-native-library react-native-kakao

여러가지 옵션이 뜨게 되는데 원하는 셋업으로 설정합니다.

그 후에 아래와 같은 명령어를 입력합니다. 셋업을 자동으로 설정합니다. 커스텀할 경우 react-native-builder-bob을 참고합니다.

npx react-native-builder-bob init

android / ios 실행 확인

$ yarn example android
$ yarn example ios

그 후 안드로이드 kakao 파일 셋팅

android/build.gradle

apply plugin: 'kotlin-android-extensions' // 추가

repositories {
  jcenter() //추가
  google()
  mavenCentral()
}

dependencies {
  //noinspection GradleDynamicVersion
  implementation "com.facebook.react:react-native:+"
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
	//추가
  implementation "com.kakao.sdk:v2-talk:2.11.0" // 친구, 메시지(카카오톡)
  implementation "com.kakao.sdk:v2-share:2.11.0" // 메시지(카카오톡 공유)
// From node_modules
}

//추가
rootProject.allprojects {
  repositories {
    maven {
      url 'https://devrepo.kakao.com/nexus/content/groups/public/'
    }
  }
} 

android/local.properties

## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Jun 23 17:43:53 KST 2022
sdk.dir=해당 sdk 경로 

android/src/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.forcdevforckakao">
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

android/src/main/res/values/kakao_strings.xml

<resources>
  <string name="kakao_app_key">카카오앱키</string>
</resources>

example/android/build.gradle

allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
        google()
        maven { url 'https://www.jitpack.io' }
				//추가
        maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/'}
    }
}

example/android/local.properties

## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Jun 23 17:43:53 KST 2022
sdk.dir=해당 sdk 경로 

example/android/app/src/main/AndroidManifest.xml

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:host="kakaolink"
                android:scheme="kakao카카오앱키" />
        </intent-filter>
</activity>

위 해당 순서로 파일 설정을 해주었을 때 문제 없이 빌드되고 작동 되었습니다.
안드로이드를 처음 하는 입장에서 리액트와 다르게 파일 구조가 달라서 많이 시행착오를 겪어서 메모 겸 작성하였습니다.

Github Packages Registry를 이용하여 패키지를 배포 하였습니다.
참고 링크 - https://velog.io/@altmshfkgudtjr/Github-Packages-Registry%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%9C-%ED%8C%A8%ED%82%A4%EC%A7%80-%EB%B0%B0%ED%8F%AC

0개의 댓글