레이블이 안드로이드인 게시물을 표시합니다. 모든 게시물 표시
레이블이 안드로이드인 게시물을 표시합니다. 모든 게시물 표시

2016년 10월 25일 화요일

맥북에서 Android Jni사용

처음으로 Android Jni를 사용하는데
헤더 파일이 생성이 안된다.....

왜지??

프로젝트 bin/classes 에서

javah -classpath ${android_home}/android.jar com.ex.hellojni


Could not find class................

윈도우에서 해보니 정상동작...뭐지??

맥에서는 경로를 못찾나보다;;

구글링 구글링...

세미콜론과 점을 찍으란다
javah -classpath ${android_home}/android.jar;. com.ex.hellojni

역시 실패

다시 구글링...
콜론과 점을 찍으란다
javah -classpath ${android_home}/android.jar:. com.ex.hellojni

오...성공!! ㅋㅋㅋ

참고로 ndk-bulider를 실행하기 위해선 .bash_profile에 NDK_HOME이 등록되어있어야한다.


오늘도 배웠다!!

참조 사이트

2015년 7월 2일 목요일

mac 안드로이드 스튜디오 단축키

아..자꾸 까먹는다..아직도 맥이 익숙하지않는다;;;;

중요 단축키... 기억좀요 제발..ㅜㅜㅜ

Option + Enter : 빠른 수정 (이클립스 코드에 빨간줄 생길 때 수정 항목 추천과 같은 기능)
Control + Space : 기본 코드 자동 완성
Control + O : Override / Implement methods
Control + Option + O : Optimize imports
Command + N : Generate code( Getters, Setters, Constructors, hashCode/equals, toString )
Control + Shift + Space : 스마트 코드 완성(예상되는 타입의 메소드또는 변수명 )
Command + Option + L : Reformat code

Command + Option + T : Surround with… (if..else, try..catch, for, synchronized, etc.)
Command + / : 한줄주석
Control + Shift + / : 블럭주석
Control + W : 연속적인 코드블럭 선택
Command + Shift + V : 클립보드 히스토리
Control + mouse over code : 간단한 설명
Shift + mouse over code : 약간 더 자세한 설명 (API version, superclass, interface)

구글 안드로이드 이클립스 ADT중지..

http://www.zdnet.co.kr/news/news_view.asp?artice_id=20140801175731

흠..ㅋㅋ
미리미리 android studio로 넘어오길 잘했다;;

두개 다 쓰고있긴한데...android studio가 더 편한건 사실이니까 ㅋㅋㅋ

2015년 7월 1일 수요일

암호화 하기


오..암호화가 되는구나;;...역시 아직 갈길이 멀어 ㅠㅠ

밑에는 원문..

-------------------------------------------------------------------------
간혹 암호화가 필요할 때가 있다. 이 경우 사용가능한 대칭키 암호화에 사용되는 자바 유틸이다.
javax패키지를 사용하며 안드로이드에서 그대로 사용이 가능하다.
Base64는 안드로이드 오픈소스에서 가져다가 사용하였다.

import java.io.UnsupportedEncodingException;

import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.SecretKey;

public class CryptoUtil {

Cipher ecipher;
Cipher dcipher;

public CryptoUtil(SecretKey key, String algorithm) {
try {
ecipher = Cipher.getInstance(algorithm);
dcipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.ENCRYPT_MODE, key);
dcipher.init(Cipher.DECRYPT_MODE, key);


} catch (javax.crypto.NoSuchPaddingException e) {
} catch (java.security.NoSuchAlgorithmException e) {
} catch (java.security.InvalidKeyException e) {
}
}

public String encrypt(String str) {
try {
// Encode the string into bytes using utf-8
byte[] utf8 = str.getBytes("UTF8");
// Encrypt
byte[] enc = ecipher.doFinal(utf8);
// Encode bytes to base64 to get a string
return Base64.encodeToString(enc, Base64.URL_SAFE|Base64.NO_WRAP);
//return String.valueOf(enc);
} catch (javax.crypto.BadPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (java.io.IOException e) {
e.printStackTrace();
}
return null;
}

public String decrypt(String str) {
try {
// Decode base64 to get bytes
byte[] dec = Base64.decode(str, Base64.URL_SAFE|Base64.NO_WRAP);
// Decrypt
byte[] utf8 = dcipher.doFinal(dec);
// Decode using utf-8
return new String(utf8, "UTF8");
} catch (javax.crypto.BadPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (java.io.IOException e) {
e.printStackTrace();
}
return null;
}

public static void main(String[] args) throws Exception {
// Generate a temporary key. In practice, you would save this key.
SecretKey key = KeyGenerator.getInstance("DES").generateKey();

// Create encrypter/decrypter class
CryptoUtil c = new CryptoUtil(key, "DES");

// Encrypt
String encrypted = c.encrypt("안녕하세요 이요삼입니다...");
System.out.println(encrypted);

// Decrypt
String decrypted = c.decrypt(encrypted);
System.out.println(decrypted);       
}

}

출처 : http://samse.tistory.com/entry/Encrypt-Decrypt-moduleDES-AES