본문 바로가기
Develop/Android

[Telegram] 안드로이드 텔레그램 API 사용하기(TDLib) - 2

by 알려 2022. 3. 5.
728x90
반응형

2022.03.05 - [Develop/Android] - [Telegram] 안드로이드 텔레그램 API 사용하기 - 1 까지 되었다면

이제 App에 API를 적용해보자.

※Telegram API가 아닌 TDLib(Telegram Database Library) 를 이용한 포스팅입니다. 
혼선을 드린점 양해 부탁드립니다.

 

하기 소스를 참고하였다.

https://github.com/indritbashkimi/TelegramExample

 

GitHub - indritbashkimi/TelegramExample: A telegram client for android created using tdlib library and built with Jetpack Compos

A telegram client for android created using tdlib library and built with Jetpack Compose - GitHub - indritbashkimi/TelegramExample: A telegram client for android created using tdlib library and bui...

github.com

하기 github 링크에 예제와 라이선스 설명 등이 있다.

 

GitHub - tdlib/td: Cross-platform library for building Telegram clients

Cross-platform library for building Telegram clients - GitHub - tdlib/td: Cross-platform library for building Telegram clients

github.com

 

README에 Building 관련된 설명이 있고 여기서  TDLib build instructions generator 

링크를 타고 가면 라이브러리를 다운로드할 수 있다.

 

하기와 같은 화면이 나오면 언어와  OS를 선택하게 되면 라이브러리가 다운로드 되게 된다. 살펴보면 웬만한 언어와 OS는 다 제공되는 것으로 보인다. 사실 모두인 거 같지만 내가 모르는 언어와 OS도 있을 수 있으니 단정 짓지는 않겠음.

다운로드한 파일의 압축을 풀면 하기와 같은 안드로이드 프로젝트가 있다. 코틀린용으로 받았지만 자바로 되어있다 아시다시피 개발하는 데는 아무런 문제가 없다. 

 

참고사항 2개가 있는데

  • 하기 링크에 코틀린으로 된 라이브러리가 있는데 이번엔 쓰지 않겠다. 어떤 내용인지는 나중에 좀 더 검토해보도록 한다.
  • https://github.com/tdlib/td/tree/master/example#kotlin
  • 그리고 내 PC환경이 macbook Bigsur환경인데 여기서 압축이 안 풀린다. 그래서 별도의 압축 프로그램을 사용해서 압축을 풀었다 압축이 안 풀리시는 분들은 참고하여주시기 바란다.

다시 돌아와서 다운로드한 라이브러리를  프로젝트 내에 복사하고 Setting을 해준다.          

 

  • settings.gradle은 하기와 같이 작성하고
include ':app', ':libtd'
  • app/build.gradle은 하기와 같이 작성한다.
dependencies {

   implementation project(':libtd')
   
}

그러고 나서 sync now를 하게 되면 최신 버전에서는 아마 라이브러리 쪽에서 빌드 에러가 날 수도 있다. 그럴 땐 libtd프로젝트의 app/build.gradle에서 아래 dependencies에 complie을 implementation으로 변경해주면 빌드 에러가 해결된다.

dependencies {
    compile 'com.android.support:support-annotations:25.0.0'
}
dependencies {
    implementation 'com.android.support:support-annotations:25.0.0'
}

 

APP환경 세팅이 완료되었다.

이제 TDLib 연동 코드를 작성해 보도록 하겠다. 연동 코드 작성은 다음 포스팅에서 하는 걸로

 

※추가사항 

일부 환경에서 하기 import에서 에러가 난다면 

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;

이렇게 바꿔주자

import android.support.annotation.IntDef;
import android.support.annotation.Nullable;

 

728x90
반응형

댓글