Skip to content

Instantly share code, notes, and snippets.

@muabe
Last active May 29, 2020 05:08
Show Gist options
  • Save muabe/f3390a9c82718050813e to your computer and use it in GitHub Desktop.
Save muabe/f3390a9c82718050813e to your computer and use it in GitHub Desktop.

#Android Wear 개발환경 준비 Google에서는 Android Wear 개발에 필요한 빌드 플러그인을 Android Studio에서 지원해주고 있습니다.
또한 앞으로 Android Studio가 베타버전이 끝나고 정식으로 릴리즈 될 경우 기존 Eclipse IDE의 빌드
환경에 플러그인을 지원하지 않는다고 합나다.
이는 Android 개발자라면 빠르게 Android Studio로 갈아타야한다는 것을 의미하기도 합니다.
하지만 현재 개발된 Eclipse 환경을 베타 버전인 Android Studio에 바로 적용하기에는
진행되고 있는 프로젝트에 따라 무리가 따를수도 있습니다.
그래서 Android Wear를 개발하기 위해 Android studio와 Eclipse의 두가지 개발환경에 대해 각각 알아보겠습니다.

###Android SDK 및 IDE 다운로드 Android Wear를 개발하기 위해 아래 링크로 SDK와 IDE를 설치합니다.

###Android SDK 및 라이브러리 Install

  1. Android Wear는 Android SDK 4.4W(킷캣웨어) 버전 이상이 필요합니다.
  • Android SDK Manager를 실행후 아래와 같이 Android 4.4W를 Install합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/4.4w.png)

2. Android Wear를 개발하기 위해선 Google Play Services라는 라이브러리가 필요합니다. - Android SDK Manager를 실행후 아래와 같이 Google Play Services와 Support Repository를 Install합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/google_play.png)

#Android Studio로 Wear개발 android Wear는 Wearable 기기에 앱을 개발하는 것을 지원합니다.
Wearable 기기에서는 인터넷 등을 지원하지 않고 앱을 다운받을수 있는 Store가 없습니다.
이때 앱을 배포하는 과정중 Google Play Store에서 앱을 다운받을수 있도록 도와줄수있는
별도의 Android 디바이스가 필요합니다.

통상적으로 별도의 Android 디바이스는 스마트폰이며 Wearable의 본체라 볼수 있습니다.
이렇게 Wearable 기기는 스마트폰 같은 본체가 있어야 되며 스마트폰에 종속적인 구조로 이루어 졌습니다.
이는 Wearable 기기에서 필요한 자원(인터넷,주소록 등등)을 Bluetooth를 이용하여 연동할수 있게 해줍니다.
Wearable과 스마트폰의 관계에 있어 Bluetooth로 상호간 통신해주는 일을
Google Play Service 라이브러리가 도와줍니다.
우리는 Google Play Service 라이브러리를 이용하여 Wearable과 통신 할수 있으며
기타 Wearable관련 기능 등을 손쉽게 사용할수가 있습니다.

  • Wearable 기기에 앱을 설치 과정에 Google play store를 탑제한 본체 디바이스가 필요합니다.
  • Wearable이 인터넷등 스마트폰의 자원을 사용하려면 스마트폰에서도 Wearable을 지원해줄 앱을 개발하여야 합니다.
  • Wearable에서 스마트폰의 자원이 필요없다면 스마트폰의 앱을 개발하지 않아도 됩니다.

``이제부터 Android Studio를 사용하여 Android Wear의 프로젝트를 생성해보겠습니다.```

###Android Studio 환경설정

  1. Android Studio 에서 SDK 설정
  • Android Studio를 처음 실행하면 아래와 같은 화면이 나오는데 환경설정을 한후 프로젝트를 생성 합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/studio_config.png)

- 화면의 ```Configure > Project Defaluts > Project Structure``` 로 이동하면
Android SDK 및 JAVA SDK Path설정을 할수 있는데 각각에 맞게 설치된 SDK 폴더를 지정해 줍니다.
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/studio_sdk.png)

###Android Studio 프로젝트 생성

  • 설정이 끝나면 New Project를 클릭하고 Application name과 Package name을 설정하여 프로젝트 생성을 시작합니다.
    아래는 Application name을 WearDev 로 하였고 Domain을 mark.com으로 하였습니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/new project.png)

- 아래 Wear를 체크하고 스마트폰과 통신도 하기 위해 Phone and Tablet 항목도 체크합니다.
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/new project2.png)

- 먼저 스마트폰의 프로젝트 생성입니다. 저는 ```PhoneApp``이름으로 생성하였습니다.
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/create_project1.png)

- Activity 모듈 선택화면인데 ```blank Activity```를 선택하였습니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/create_project2.png)

- 이제는 Wear Activity 모듈 선택화면인데 현재 선택할수 있는 항목이 ```blank Activity``` 하나 있네요

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/create_project3.png)

- Wear 앱 이름을 설정하고 Finish를 하면 프로젝트가 생성 됩니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/create_project4.png)

###Android Studio 프로젝트 보기

  • 프로젝트 내에 mobile과 wear 두개의 모듈이 생성된것을 볼수 있습니다.
  1. mobile은 스마트폰의 앱관련 개발소스이고
  2. wear는 wearable 관련 앱 개발 소스입니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/IDE Basic.png)

- 위에 표시된 3번을 클릭하여 Wear Square를 선택하면 아래와 같이 스마트 워치의 Design View를 확인 하실 수 있습니다.
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/IDE Basic2.png)

#Wear Device debuging 시작 Wear Device를 실행 및 Debug하기 위해서 스마트폰에 Android Wear 앱을 설치하여야 합니다.
Android Wear 앱은 Google Play Store에서 손쉽게 다운 받을수 있습니다.
※디버깅은 LG GWatch Device를 사용합니다.

  • Android Wear 앱의 실행 화면 입니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/android_wear1.png)

  • Bluetooth debuging
    android Wear app를 실행하고 우측 상단을 설정을 클릭하고 아래와 같이 블루투스를 통해 디버깅을 선택합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/android_wear2.png)

  • G Watch 디버깅 설정
    1. G Watch를 켜고 설정 > 정보 > 빌드번호항목을 연타하게되면
      설정 메뉴에 개발자 옵션이 생기게 됩니다.
    2. 개발자 옵션으로 들어가 보면 블루투스 스누프로깅, ADB디버깅, 블루투에 대한 디버그
      항목이 있는데 모두 사용으로 체크를 합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/watch1.png)

  • Adb Forward 디버깅을 하기위해선 한가지 더 필요한 작업이 있는데 Adb forward를 해줘야 Wear Device를 디버깅 할수 있게 됩니다.
    1. 첫번째로 스마트 폰에 USB를 연결켜 줍니다.(의외로 중요)
    2. 커맨드 라인에 아래 두개의 커맨드를 실행 시킵니다.
adb forward tcp:4444 localabstract:/adb-hub
adb connect localhost:4444

EX)
c:\android_sdk\sdk\platform-tools\adb forward tcp:4444 localabstract:/adb-hub
c:\android_sdk\sdk\platform-tools\adb connect localhost:4444

```
-  모든 작업을 마쳤으면 Android Wear 앱을 실행시켜 ```설정 > 블루투스를 통해 디버깅```에<br> 호스트가 연결됨으로 된것을 확인 할수 있습니다.
<br>
 ![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/android_wear3.png)
<br><br>
   1. 이제 Android Studio로 돌아가서 메뉴에 ```Run > Wear``` 실행하면<br>아래와 같이 G Watch Device를 확인할수 있습니다.
<br>
 ![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/android_wear_run.png)
<br><br> 
   2. G Watch의 Hello World 앱 실행 화면
<br>
 ![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/hellow_wear.png)
<br><br> 

#Eclipse로 Wear개발 Eclipse로 Wear을 개발하기 위해선 Wearable1.0.0라이브러리와 Google Play Service 라이브러리가 필요합니다.

  • Google Play Service 라이브러리는 android sdk설치경로\extras\google\google_play_services\libproject
    있기 때문에 해당 경로로 프로젝트를 Import합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/import1.png)

  • Wearable1.0.0 라이브러리는 아래 링크로 다운 받을수 있고 또는 새로 추출하셔도 무방합니다.
    1. [Wearable1.0.0 다운로드]
    2. Wearable1.0.0 추출 방법
      Android SDK설치한 폴더에서 아래 경로로 이동하면 wearable-1.0.0.aar파일이 있습니다.
./extras/google/m2repository/com/google/android/support/wearable/1.0.0/
이파일의 확장자를 zip으로 변경 후 압축을 해제하면 해당 폴더에 classes.jar파일이 있습니다.<br>

이파일을 libs 폴더로 이동 시킵니다.

  • Android Wear Tempplate 프로젝트 Import
    1. Android Wear에 관련된 템플릿을 지원하지 않기 때문에
      템플릿 프로젝트를 다운받아 Import합니다. [Android Wear 템플릿 프로젝트 다운로드]
    2. 템플릿 프로젝트를 Import하면 DemoWearApp프로젝트가 생성되는데 Properties설정에서 위에서 Import한 두개의 라이브러리를 Dependencies합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/import2.png)

3. 프로젝트를 Run 했을때 Wear Device debuging설정이 되었다면 아래와 같이 G Watch Device가 보이게 됩니다.
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/import3.png)

4. Eclipse에서 G Watch의 Hello World 앱 실행 화면
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/hellow_wear.png)

Wearable을 지원하는 스마트폰 앱 연동

Wearable Device에서 스마트폰의 자원을 사용하기 위해선 스마트폰에 Wearable과
통신할수 있는 별도의 앱을 만들어야 합니다.

  • File > New > Project > Android Application project로 이동하여 Android 프로젝트를 생성합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/eclipse_project1.png)

- Properties설정에서 Google Play Services 라이브러리를 Dependencies합니다.
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/eclipse_project2.png)

- 프로젝트에 res/raw 폴더와 res/xml 폴더를 생성합니다. - Wearable로 제작된 앱의 APK파일을 res/raw 복사하여 넣습니다. - res/xml 폴더에 wearable_app_desc.xml 명으로 xml 파일을 생성합니다.
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/floder.png)

- 생성한 xml파일에 아래와 같이 xml을 작성합니다. ```xml 1 1.0 wearable_app ``` ``` 1.package 속성에 wearable 프로젝트의 패키지 명을 입력합니다. 2.rawPathResId에는 res/raw 폴더에 저장한 APK 파일명을 입력 합니다. ```
  • AndroidManifest.xml의 application 노트 밑에 아래와 같이 Meta data 태그를 입력합니다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
......생략
    <application>
        .......생략
         <!-- 메타데이터 입력-->
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
        <meta-data android:name="com.google.android.wearable.beta.app" android:resource="@xml/wearable_app_desc"/>
        ......생략
    </application>
</manifest>
  • 모든게 완료되었으면 프로젝트를 실행합니다.
  • 이후 Android wear 앱에서 앱 동기화를 실행합니다.

![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/wear_sync.png)

- 이제 스마트폰과 G Watch에 앱이 들어가 있는것을 확인할수 있습니다.
![](https://raw.githubusercontent.com/JaeWoongOh/jaewoongoh.github.com/master/gist/images/etc/wear_start.png)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment