100%  FF
95%  F2
90%  E6
85%  D9
80%  CC
75%  BF
70%  B3
65%  A6
60%  99
55%  8C
50%  80
45%  73
40%  66
35%  59
30%  4D
25%  40
20%  33
15%  26
10%  1A
5%  0D
0%  00

퍼센트낮을수록 투명해짐


android:Theme.Holo.Light requires API level 11 (current min is 8)



Mainfest.xml

   <uses-sdk android:minSdkVersion="8"  android:targetSdkVersion="21" />




Style.xml

<style name="NNTheme" parent="android:Theme.Holo.Light">

<item name="android:windowNoTitle">true</item>

        <item name="android:windowContentOverlay">@null</item>

</style>



문제.................



해결은.. 골뱅이 추가

<style name="NNTheme" parent="@android:Theme.Holo.Light">

http://dkatlf900.tistory.com/36

빨간부분 추가, 프로젝트 내에 app-> build.gradle 파일 열고 

 apply plugin: 'com.android.application'



import org.apache.tools.ant.taskdefs.condition.Os
def getNdkBuildPath() {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())

    def command =  properties.getProperty('ndk.dir')
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        command += "\\ndk-build.cmd"
    
else {
        command += "/ndk-build"
    
}

    return command
}

android {
    compileSdkVersion 23
    
buildToolsVersion "23.0.2"

    
defaultConfig {
        applicationId "andcast.hhh.test"
        
minSdkVersion 21
        
targetSdkVersion 23
        
versionCode 1
        
versionName "1.0"
    
}
    buildTypes {
        release {
            minifyEnabled false
            
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
}
        debug {
        }
    }


    sourceSets.main {
        // Compile
 Native Library 위치하는 경로를 설정합니다.
        
jniLibs.srcDir 'src/main/libs'

        
// 
여기에 JNI Source 경로를 설정하면 Android Studio에서 기본적으로 지원하는 Native
        // Library Build
 이루어집니다 경우에 Android.mk Application.mk
        // 
자동으로 생성하기 때문에 편리하지만세부 설정이 어렵기 때문에 JNI Source
        // 
경로를 지정하지 않습니다.
        
jni.srcDirs = []
    }

    ext {
        // 
아직은 Task 내에서 Build Type 구분할 방법이 없기 때문에  Property
        // 
이용해 Native Library Debugging 가능하도록 Build  결정합니다.
        
nativeDebuggable = false
    
}

    // NDK
 ndk-build 명령을 이용하여 Native Library Build하기 위한 Task 정의합니다.
    //noinspection GroovyAssignabilityCheck
    
task buildNative(type: Exec, description'Compile JNI source via NDK') {
        if (nativeDebuggable) {
            commandLine getNdkBuildPath(), 'NDK_DEBUG=1''-C', file('src/main').absolutePath
        else {
            commandLine getNdkBuildPath(), '-C', file('src/main').absolutePath
        }
    }

    // App
 Java Code Compile  buildNative Task 실행하여 Native Library 같이
    // Build
되도록 설정합니다.
    
tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn buildNative
    }


}




gradle.properties 에

android.useDeprecatedNdk=true

추가!



Project Structure -> SDK Location -> Android NDK Location 경로 잘 되있는지 확인




빌드하면 끝!





ex) #F2000000


100%  FF
95%  F2
90%  E6
85%  D9
80%  CC
75%  BF
70%  B3
65%  A6
60%  99
55%  8C
50%  80
45%  73
40%  66
35%  59
30%  4D
25%  40
20%  33
15%  26
10%  1A
5%   0D
0%   00



Android-NDK (http://developer.android.com/sdk/ndk/index.html)


1. ndk 받자!! -> 원하는 폴더에 풀자 , 그냥 드라이브 최상단에 넣자!



2. Install Eclipse C/C++ Development Tools

After Eclipse is installed, run it and go to the menu->Help->Install New Software.  Select the Indigo or CDT update site.  SelectProgramming Languages and select/check C/C++ Development Tools

Click Next and install.

C,C++ 개발킷 설치!




3. Add Androind NDK path into the Eclipse Android Preferences:

Open the Eclipse Preference (menu -> Window->Preferences), navigate to Android->Native Development then enter the path (yes, the same path as in step 5 again — frankly I am not sure if just doing this step without doing step 5 is enough, so just do both). If you don’t see this option on the Eclipse Preference, restart Eclipse.


NDK 설정 완료!




4. 밑에 설명처럼 하면 끝!!!! 프로젝트 클린하고 라리브러리 폴더 새로고침한후에 안을 들여다 보면 .so 파일이 생성되어있다!!!!!!!!




확인할점!!!!

jni 폴더 -> Android.mk


LOCAL_MODULE    := ccc-library

LOCAL_SRC_FILES := ccc-decoder.c

#############################################

LOCAL_MODULE => 라이브러리 이름 나중에 자바소스에서 라이브러리 부를때 이이름으로 부른다!!!!!

ex)

static {

        System.loadLibrary("ccc-library");

}



LOCAL_SRC_FILES => jni 폴더에 있는 c 파일을 써준다. 어찌하다가 cpp파일 생성되어 cpp로 설정되는 경우있는데 그냥 c 파일로 설정 해주자!! c파일없음 cpp로 하고~~

#############################################






5. so 파일도 생성됬으니 프로젝트->properties-> android -> is library 체크해주고 다른프로젝트에서 가져다 쓰자!





opencv 팁

# OpenCV - opencv manager package was not found 인스톨 따로 안하고 실행시킬수 있다

OPENCV_CAMERA_MODULES:=on

OPENCV_INSTALL_MODULES:=on



절대 경로 변경

#include ../../sdk/native/jni/OpenCV.mk

include D:/open_cv/sdk/native/jni/OpenCV.mk










\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

참고

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\




http://thdev.net/474


생성된 프로젝트 목록을 보면 jni 폴더가 기본적으로 생성이되며, 바로 위에서 작성한 이름인 AndroidNDK라는 이름의 cpp와 Android.mk 빌드파일이 생성되었습니다.


 실제로 이렇게 하면 문제가 있습니다. #include <jni.h> 가 추가된 AndroidNDK.cpp가 있지만 빌드에는 문제가 없지만 실제로 프로젝트에 오류가 나게 됩니다. 그 오류를 해결 하기위한 방법을 설명하겠습니다. 이 방법은 모든 NDK 프로젝트를 만드실 때 항상 추가해주셔야 하는 부분입니다.

 프로젝트 오른쪽 마우스를 클릭하여 Properties 로 이동합니다. 프로젝트 설정을 뛰우면 아래와 같이 C/C++ Build와 C/C++ General 2개가 추가된것을 확인할 수 있습니다. C/C++ General->Paths and Symbols를 선택합니다. 여기에 새로운 경로를 하나 추가해주어야 합니다. 추가하기 전에 해주어야 할 사항이 있습니다. 보시는 것과 같이 C:\android-ndk\ .. 처럼 모든 경로가 표시가 됩니다. 이 경우 해당 PC에서는 문제가 없지만 ndk 경로가 D:\로 이동한다면 문제가 생기기 쉽습니다. 이런 부분을 해결하기 위해서 모든 OS에서는 Path라는게 있습니다.


 이 Path를 등록해주면 모든 PC에 같은 PATH 이름만 있다면 어디든 문제없이 빌드가 가능해질 수 있으니 이 부분을 추가해주면 됩니다. PATH 등록 부분은 윈도우에서 하는 방법을 설명합니다.

 윈도우 8을 기준으로 설명하는 부분이므로 다른 버전의 윈도우와는 다를 수 있습니다.

 제어판을 실행하고, 시스템, 보안 탭을 클릭합니다.


아래의 메뉴에서 "시스템"을 선택합니다.


"고급 시스템 설정"을 선택합니다.


다른 OS에서는 내 컴퓨터의 오른쪽 마우스를 선택하여 -> 시스템 설정을 선택하셔도 됩니다.

고급탭에 이동하시면 "환경 변수"가 있습니다. 이 환경 변수를 클릭합니다.


환경 변수에서 "추가" 버튼을 클릭합니다. 이미 NDKROOT 가 있으시다면 등록하시지 않으셔도 됩니다.


 이름은 NDKROOT 또는 NDK_ROOT 등으로 구분되는 이름을 추가하시면 됩니다. 이 경로는 NDK를 설치한 경로를 적어주시면 됩니다. 저는 C:\android-ndk가 기본 경로이므로 아래와 같이 적어주었습니다.


Eclipse를 재시작하고나야 다시 등록이 가능합니다. 아까와 동일한 메뉴에서 c,cpp에 대한 Include를 해주면 됩니다.

오른쪽의 Add..를 클릭하고 다음의 경로를 추가해주시면 됩니다.

 ${NDKROOT}\platforms\android-9\arch-arm\usr\include

${NDKROOT} 의 경우는 Path 등록한 이름이어야 합니다.


 위와 같이 등록이 완료되면 Project->clean 으로 가서 프로젝트 클린을 한번해줍니다. 그리고 ctrl+b를 눌러 프로젝트 빌드를 해주시면 됩니다. 이것보다 간단한 방법을 사용할려면 아래의 내용을 더 추가해주시면 됩니다.

 이번에는 C/C++ Build를 눌러 Behaviour 를 선택하시고, Clean을 체크해제하시고, Build on resource save (Auto build)와 Build 를 체크합니다. 아래와 같이 빈 창으로 두시면 됩니다. 이렇게 하면 클린만 하시면 자동으로 빌드가 이루어집니다. (단점은 클린할 때마다 빌드가 되니 클린 할때도 현재 프로젝트에 대해서만 클린하시기 바랍니다.)






////////////     http://tools.android.com/recent/usingthendkplugin ////////////////////////////////


ADT 20 includes an NDK plugin that provides support for building and debugging NDK projects in Eclipse. This document describes how to install and use the NDK plugin.


Installation

The NDK plugin currently works with CDT 7.0.2 or CDT 8.0.2.
  1. Download Eclipse for Java.
  2. Install CDT from Eclipse update site http://download.eclipse.org/tools/cdt/releases/indigo.
  3. Install Android SDK + NDK Plugins from Eclipse update site https://dl-ssl.google.com/android/eclipse/
Using the NDK Plugin

1. First set the path to SDK and NDK:

Eclipse -> Window -> Preferences -> Android -> set path to SDK

Eclipse -> Window -> Preferences -> Android -> NDK -> set path to the NDK


2. Right click on an Android project and select Android Tools -> Add native support.
Note that you will not be able to add native support if the project already has C/C++ nature.

At this point, you will be able to build your applications using Project -> Build All.

Debugging native applications

1. Update your build config to include “NDK_DEBUG = 1”.

Right click project -> properties -> C/C++ Build:



2. Set a breakpoint in your C code.
3. Right click on your project, select Debug As -> Android Native Application

Note: There is a delay of a few seconds between when the activity is launched and when native debugging starts. If your code is already executed by that point, then you won’t see the breakpoint being hit. So either put a breakpoint in code that is called repetitively, or make sure that you call JNI code after you see that ndk-gdb has connected.

Known Issues

1. Eclipse does not automatically find the include paths to all the NDK headers on Windows. This issue will be fixed in the next update (20.0.1) when it is released.
2. Eclipse does not automatically find the include paths with CDT 8.1.0 (Juno). This issue is tracked in Bug 33788.









======================================================================================================














////////////    http://stackoverflow.com/questions/27462754/compiling-hello-jni-failure-in-eclipse-only-when-opening-the-hello-jni-c-file-in  ////////////////////////////////




I have been trying endlessly to build the sample HelloJni sample project for the Android NDK.

How I set up the environment:

I followed the instructions of the getting started in the docs: android-ndk-r10d\docs\Getting_Started/html/index.html:

  1. Downloaded Eclipse Luna
  2. Downloaded the Android SDK
  3. Downloaded the Android NDK: android-ndk-r10d
  4. Set the NDK installation folder in eclipse in preferences window -> android -> NDK.
  5. Imported the hellp-jni sample.
  6. Right click on the HelloJni Project -> Android tools -> Add native support.
  7. Cleaned and Built the project.
  8. Ran on my device the HelloJni library (not the tests)

And the app is running and everything is WORKING and I can see the generated .so file per architecture in the libs folder of the project (for every architecture, for example armebi, mips, etc...)

Here is a Print Screen showing everything is working:

enter image description here

Now here comes the strange part...

The Problem:

If I open the hello-jni.c file for editing or viewing in eclipse, I suddenly see compilation errors and I can't build and can't run the project anymore...

Here is a Print Screen showing that after i open the file, I suddenly get compilation errors:

enter image description here

What I have already tried but failed:

  1. Adding the Android Native Nature, then removing it by: Deleting the .project file, the buildCommand tag of: org.eclipse.cdt.managedbuilder.core.genmakebuilde, the buildCommand tag of: org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder and removing the lines: [nature]org.eclipse.cdt.core.cnature[/nature] [nature]org.eclipse.cdt.core.ccnature[/nature] [nature]org.eclipse.cdt.managedbuilder.core.managedBuildNature[/nature] [nature]org.eclipse.cdt.managedbuilder.core.ScannerConfigNature[/nature] removing the .cproject and all compiled files. Then adding back the Android Native Nature.

According to this stackoverflow link: Eclipse ADT - Unresolved inclusion jni.h

Failed

  1. Once I got the error of (I am not getting it anymore): Unable to launch cygpath. Is Cygwin on the path?] java.io.IOException: Cannot run program "cygpath". So I Googled and I changed the build settings to give the absolute path of my NDK installation folder:

According to this stackoverflow link: Unable to launch cygpath in android

Here is a Print Screen: enter image description here

Failed

  1. Changing the Used tools from Android GCC Compiler to GCC C Compiler

according to this stackoverflow link: Android NDK build, Method could not be resolved

Here is a Print Screen: enter image description here

Failed

  1. Copying an eclipse Luna installation from a friend that has the project working for him.

Failed

I have been spending hours on this and I couldn't find any solution to why this is happening.




======================================================================================================








http://helloworld.naver.com/helloworld/textyle/8794

참고






일단 NDK 빌드환경을 만들어 보도록 하겠습니다.


1. 설치전 준비사항

  • Java의 필수 설치 필요함. 환경변수 설정도 완료 필요함
  • sdk설치. 나중에 머 어쩌고 뜨는거 보기 싫다면

2. NDK 다운로드


3. 압축을 풀고 싶은곳에 풀도록 합니다. 나중에 세팅때문에 패스가 좀 짧으면 좋기는 합니다만


4. Cygwin설치

  • 윈도우 환경에서 리눅스처럼 사용하도록 만들어진 녀석인데, 편하기도 하고 안 편하기도 함.
  • Site : http://www.cygwin.com

5. Cygwin설치 상세
  • Install from Internet선택
  • 드라이브 바로 아래가 편함... / All Users
  • 미러사이트를 선택해야하는데... 아무거나 해도 되지만. http://ftp.daum.net/cygwin/ 이걸로 한다.
  • 다운로드할 패키지를 선택함
    - devel/gcc-core: GNU Compiler Collection (C, OpenMP)
    - devel/gcc-g++: GNU Compiler Collection(C++)
    - devel/make: The GNU version of the 'make' utility


6. Cygwin bashrc수정

  • 설치된 경로 : C:\cygwin\home\[계정명]\.bashrc
* 저는 C:\cygwin에 설치하였습니다. 파일이 존재하지 않으면 cygwin을 한번 실행한후에 다시 들어가면 나옵니다.
  • 추가해야 할 내용. (제일 아래에 추가하시면 됩니다.)
PATH=$PATH:.:/cygdrive/c/cygwin/bin:/cygdrive/c/[NDK설치경로]:/cygdrive/c/[SDK설치경로]/tools:/cygdrive/c/[SDK설치경로]/platform-tools
export PATH

NDK_PROJECT_PATH=.
export NDK_PROJECT_PATH


7. 확인

  • exit하여서 나오고 다시 shell을 실행하고, adb를 쳤을때 당황스럽지 않으면 완료 된것임

출처 - http://mrgamza.tistory.com/42


이전에 인터넷에서 나와 있는 녀석들은 이클립스를 이용하여 개발된 버전들이 아니라서, 그냥 cygwin에서 쳐서 해결을 하였던 부분들이 많았음.

그래도 이제 좀 편해졌으니 다행이긴 하지만...

NDK 다운로드 등에 대한 부분은 저는 설명을 따로 하지는 않겠음.

1. Java Class File 만들기

다들 아시겠지만... C파일과 Interface 역활을 하여줄 Class 파일이 존재하여야 한다.

그렇게 어렵지는 않으니 하나 하나 하다보면 빌드완성을 보게 될것임.

다음과 같이 작성하도록 함.

1
2
3
4
5
6
7
8
9
10
11
public class NativeCall
{
    static
    {
        // {project-path}/libs/armeabi/libhellojni_lib.so 파일을 읽어들입니다.
        System.loadLibrary("hellojni_lib");
    }
     
    public native String getJNIMessage(); // String형식으로 데이터를 가져옴
    public native int add(int a, int b); // 메소드 이름처럼 두숫자를 더해서 리턴
}


2. Java Class File로 jni Header File(.h) 만들기

위에서 Java Class파일을 만들었기 때문에, 빌드를 한번 해주게 된다면 {project-path}/bin/classes/ 폴더 아래에 자신이 만든 package name 아래에 .class파일들이 슬며시 들어가 있습니다. 이번 작업이 안된다면, 꼭 Clean이나 Build를 한번 해주길 바람. 또한 javah 관련하여서, 물어보지 말길 바람. 안드로이드 개발 작업하면서 path를 지정안해둔것은 개발 안하겠다는 소리와 같으므로...


C:{project-path}/bin>javah -classpath ./classes/ -jni com.example.hellojni.NativeCall


다르게는 이렇게 하셔도 됩니다.


C:{project-path}/bin/classes>javah -jni com.example.hellojni.NativeCall


위와 같이 저는 package name이 com.example.hellojni입니다. 물론 기본 패키지명 아래에 Java Class를 만들었고요.


다른점은 .h파일이 생성되는 위치라고 생각하시면 됩니다. 자신이 작업한 폴더에 파일이 생성되겠죠?


이 생성된 파일을 다음의 위치로 옮깁니다.


{project-path}/jni/


몰론 처음에는 존재하지 않는 폴더입니다.

탐색기에서 작업을 하셔서 옮기시면 손쉽게 옮기시리라 믿습니다.


이렇게 옮겼는데, 이클립스에서 파일이 존재하지 않는다고 생각되시면, 프로젝트를 클릭하시고, F5를 눌러주시기 바랍니다. 새로고침.


3. .c 파일 만들기

jni가 C로 만든 녀석들을 호출하는것은 당연히 알고 있으시리라고 믿습니다. 그래서 빌드를 할수 있도로 C파일을 작업하여 줍니다. 기본적으로 현재 {project-path}/jni/에 존재하는 h파일에 대해서, 작성을 하여 주면 되는데요.


/jni/위에 마우스 오른쪽 클릭 > NewFile > 만들 파일명

위에 저희는 hellojni_lib로 사용을 하기로 하였죠? 통일성을 위해서, hellojni_lib.c로 지정하여 줍니다.


그리고 다음을 추가하여 줍니다.


1
2
3
4
5
6
7
8
9
10
11
#include "com_example_hellojni_NativeCall.h"
 
JNIEXPORT jstring JNICALL Java_com_example_hellojni_NativeCall_getJNIMessage(JNIEnv *env, jobject obj)
{
    return (*env)->NewStringUTF(env, "Hello JNI!");
}
 
JNIEXPORT jint JNICALL Java_com_example_hellojni_NativeCall_add(JNIEnv *env, jobject obj, jint a, jint b)
{
    return a + b;
}
분명히 위와 같이 하면 안된다고 말씀하시는 분들이 있으실것 같아서, 설명을 드리자면...
저희가 저위에서 Java Class를 만들고, 그 아래에서 .h파일을 만들었습니다. 그 header 파일 안에 함수원형이 존재하게 되는데요. 다음과 같습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_hellojni_NativeCall */
 
#ifndef _Included_com_example_hellojni_NativeCall
#define _Included_com_example_hellojni_NativeCall
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_example_hellojni_NativeCall
 * Method:    printFromJNI
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_com_example_hellojni_NativeCall_getJNIMessage
  (JNIEnv *, jobject);
 
/*
 * Class:     com_example_hellojni_NativeCall
 * Method:    Add
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_com_example_hellojni_NativeCall_add
  (JNIEnv *, jobject, jint, jint);
 
#ifdef __cplusplus
}
#endif
#endif
자... 위에서 저는 생성된 원형을 가져와서 파라메터의 이름만 정의를 하여 주었습니다. JNI에 대한 심도 깊은 부분은 저도 공부를 하고 있는지라... 함수는 잘 모릅니다. 질문하셔도 잘 모릅니다. 아무래도 저 위에 부분이 기본적인듯. 문자 만들기와 머 그런정도... 나머지 문법은 C++을 따르기 때문에 그냥 하시면 됩니다.

4. Android.mk 파일 생성
/jni/에 파일을 하나 더 생성하도록 합니다.
Android.mk 파일입니다. 다음과 같이 타이핑하여 줍니다.

1
2
3
4
5
6
7
8
LOCAL_PATH := $(call my-dir)
 
include $(CLEAR_VARS)
 
LOCAL_MODULE := hellojni_lib
LOCAL_SRC_FILES := hellojni_lib.c
 
include $(BUILD_SHARED_LIBRARY)
일단 이렇게 까지 합니다. 다른 분들은 cygwin에서 ndk-build를 하면 된다고 하는데, 저랑 안맞나 봅니다. 정말 잘 안되서... (사실적으로 폴더 변경등을 하여서 적용하면 될것 같은데...) 이것보다 더 쉬운 방법을 찾아 나섰습니다.


5. Eclipse NDK 설정

프로젝트명에 마우스 올리시고, 프로젝트 설정으로 이동을 합니다. 단축키 Alt + Enter

탭에서 Builders를 선택하고, New를 선택하여 주세요.

그렇게 되면, type을 물어보는데. Program을 선택하여 주도록 합니다.

그리고 다음과 같이 설정하여 주도록 합니다.


첫번째 탭



두번째 탭




세번째 탭





이렇게 하시고, 실행을 하시거나, Clean을 누르게 되면, ndk-build.cmd가 자동으로 실행이 되며, 빌드가 자동으로 됩니다.

터미널에 저런식이 아니고, 빨갛게 나오게 된다면, 잘못하신겁니다.



끝.


출처 http://mrgamza.tistory.com/48


+ Recent posts