2015년 1월 22일 목요일

AndroidNote - Android Studio에서 라이브러리 사용과 에러 : 방법 1



다음 지도 API을 android studio에서 외부 library로 사용하려 했지만 실행할 때 오류가 발생했다.

라이브러리 파일 추가

Android Daum Map 라이브러리는 libDaumMapAndroid.jar 와 아키텍쳐별로libMapEngineApi.so 두개의 바이너리로 구성되어 있습니다.
주어진 압축파일 libs 에 있는 파일들을 해당 프로젝트 /libs/ 로 모두 복사 해야 합니다.

AndroidManifest.xml 에 Permission 추가

<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
</uses-permission>
오류 내용
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427): Can`t load DaumMapEngineApi.so file
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427): java.lang.UnsatisfiedLinkError: Couldn't load DaumMapEngineApi from loader dalvik.system.PathClassLoader[dexPath=/data/app/daum.net.testdaummap-5.apk,libraryPath=/data/app-lib/daum.net.testdaummap-5]: findLibrary returned null
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at java.lang.Runtime.loadLibrary(Runtime.java:358)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at java.lang.System.loadLibrary(System.java:526)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at net.daum.mf.map.n.api.NativeMapLibraryLoader.loadLibrary(NativeMapLibraryLoader.java:33)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at net.daum.mf.map.n.api.NativeThread.<clinit>(NativeThread.java:6)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.opengl.alt.GLSurfaceView.setRenderer(GLSurfaceView.java:306)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at net.daum.android.map.MapView.init(MapView.java:44)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at net.daum.android.map.MapView.<init>(MapView.java:56)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at net.daum.mf.map.api.MapView.<init>(MapView.java:410)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at java.lang.reflect.Constructor.constructNative(Native Method)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.view.LayoutInflater.createView(LayoutInflater.java:600)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.app.Activity.setContentView(Activity.java:2010)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at net.daum.android.map.openapi.sampleapp.demos.SearchDemoActivity.onCreate(SearchDemoActivity.java:48)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.app.Activity.performCreate(Activity.java:5426)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.app.ActivityThread.access$900(ActivityThread.java:161)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.os.Handler.dispatchMessage(Handler.java:102)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.os.Looper.loop(Looper.java:157)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at android.app.ActivityThread.main(ActivityThread.java:5356)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at java.lang.reflect.Method.invokeNative(Native Method)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at java.lang.reflect.Method.invoke(Method.java:515)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
01-16 10:42:01.668: E/NativeMapLibraryLoader(3427):  at dalvik.system.NativeStart.main(Native Method)


01-16 10:42:01.678: E/AndroidRuntime(3427): FATAL EXCEPTION: main
01-16 10:42:01.678: E/AndroidRuntime(3427): Process: daum.net.testdaummap, PID: 3427
01-16 10:42:01.678: E/AndroidRuntime(3427): java.lang.RuntimeException: Unable to start activity ComponentInfo{daum.net.testdaummap/net.daum.android.map.openapi.sampleapp.demos.SearchDemoActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class net.daum.mf.map.api.MapView
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.ActivityThread.access$900(ActivityThread.java:161)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.os.Handler.dispatchMessage(Handler.java:102)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.os.Looper.loop(Looper.java:157)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.ActivityThread.main(ActivityThread.java:5356)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at java.lang.reflect.Method.invokeNative(Native Method)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at java.lang.reflect.Method.invoke(Method.java:515)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at dalvik.system.NativeStart.main(Native Method)
01-16 10:42:01.678: E/AndroidRuntime(3427): Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class net.daum.mf.map.api.MapView
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.view.LayoutInflater.createView(LayoutInflater.java:626)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.Activity.setContentView(Activity.java:2010)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at net.daum.android.map.openapi.sampleapp.demos.SearchDemoActivity.onCreate(SearchDemoActivity.java:48)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.Activity.performCreate(Activity.java:5426)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
01-16 10:42:01.678: E/AndroidRuntime(3427):  ... 11 more
01-16 10:42:01.678: E/AndroidRuntime(3427): Caused by: java.lang.reflect.InvocationTargetException
01-16 10:42:01.678: E/AndroidRuntime(3427):  at java.lang.reflect.Constructor.constructNative(Native Method)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.view.LayoutInflater.createView(LayoutInflater.java:600)
01-16 10:42:01.678: E/AndroidRuntime(3427):  ... 22 more
01-16 10:42:01.678: E/AndroidRuntime(3427): Caused by: java.lang.UnsatisfiedLinkError
01-16 10:42:01.678: E/AndroidRuntime(3427):  at net.daum.mf.map.n.api.NativeMapLibraryLoader.loadLibrary(NativeMapLibraryLoader.java:42)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at net.daum.mf.map.n.api.NativeThread.<clinit>(NativeThread.java:6)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at android.opengl.alt.GLSurfaceView.setRenderer(GLSurfaceView.java:306)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at net.daum.android.map.MapView.init(MapView.java:44)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at net.daum.android.map.MapView.<init>(MapView.java:56)
01-16 10:42:01.678: E/AndroidRuntime(3427):  at net.daum.mf.map.api.MapView.<init>(MapView.java:410)
01-16 10:42:01.678: E/AndroidRuntime(3427):  ... 25 more


그래서 구글을 6-7시간을 해멘 끝에 답을 찾았다.(OTL)

최고의 도움을 받은 링크(영어 주의)

    

일단 이런 식으로 /libs/에 다 넣어져 있는데 이 부분을 *.so 파일은 /libs/가 아니라 /lib/라는 폴더를 생성한 후 이동 시켜야 한다. 그러면 오른쪽의 화면과 같이 되는데 이 부분에서 꼭! /lib/armeabi/libDaumMapEngineApi.so 파일이 포함되게 .zip 파일로 만든 후 확장자를 .jar로 변경하고 /libs/ 폴더에 넣어 준다.

그 후에 jar 파일을 선택 후 오른쪽 클릭을 하게 되면 "Add As Library..."라고 있는데 이 부분을 클릭 해준다.


gradle 부분은 이렇게 작성하도록 한다.

그러면 제대로 library가 추가가 되었다.

정리하자면 자동을 .so 파일을 include를 안 해줘서 강제로 jar 파일로 만들어 포함시키는 것이다.

다른 사람은 이런 고통을 안 받기를 고대한다...ㅠㅠ