2014년 8월 27일 수요일

Perl 사용하지 않는 png 이미지 찾기

사용하지 않는 png 이미지 찾아 result.txt 로 출력하는 perl.


#!/usr/bin/perl

# SearchToNotUsePng.pl
# seesky89 20140826
# usage :
#    Android Application 개발시 사용하지 않는 png 이미지 제거를 위해 만듬.
#    cgywin(for Windows) 또는 리눅스에서 아래 명령 입력(상위 폴더기준)
#    perl SearchToNotUsePng.pl
#    정확성을 위해 gen, bin 폴더는 삭제 필요.

use strict;
use warnings;
use File::Find;
use File::Find qw(find);
use Cwd;


my $dir = '.';

open FH, ">", "result.txt" or die "$!\n";

my $mainDir = getcwd;
print FH "Search to not use resource. you need to check.\n";
print FH $mainDir, "\n";
print FH "------------------------------------------------------------\n";

find(\&find_use_file, $dir);

close FH;

print ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";
print "Check to result.txt\n";
print ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";

sub find_use_file {

    my $file = $_;
    my $currentDir = getcwd;
    
    if (-d $file) {
        #print "skip dir : $file\n";
    } elsif (-f $file) {
        #print "file : $file\n";

        if (/\b.9.png\b/i) {
            print "search file : $File::Find::name\n";

            # filename.png
            my $lastindex = rindex($file, '.9');
            my $search = substr($file, 0, $lastindex);

            $currentDir = getcwd;
            chdir('../..');

            my $ret = system("find . -name -prune -o -type f \( -name '*.java' -o -name '*.xml' -o -name '*.c' \) -print0 | xargs -0 grep --color -n $search");
            if($ret != 0) {
                print FH $File::Find::name, "\n";
            }

            chdir($currentDir);

        } elsif (/\b.png\b/i) {
            print "search file : $File::Find::name\n";
            
            # filename.png
            my $lastindex = rindex($file, '.');
            my $search = substr($file, 0, $lastindex);


            $currentDir = getcwd;
            chdir('../..');

            my $ret = system("find . -name -prune -o -type f \( -name '*.java' -o -name '*.xml' -o -name '*.c' \) -print0 | xargs -0 grep --color -n $search");
            if($ret != 0) {
                print FH $File::Find::name, "\n";
            }
            
            chdir($currentDir);
        } else {
            #print "skip other file : $file\n";
        }
    }
}

Linux find 명령 활용한 파일내 string 찾기

안드로이드 envsetup.sh 파일을 참고하여 작성된 function.

아래 파일을 sh 파일로 저장후 cygwin 이나 Linux 환경에서 동작.

". filename.sh" 실행후, functionName string 으로 사용.


function jgrep()
{
find . -name .repo -prune -o -name .git -prune -o  -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
}

function cgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep --color -n "$@"
}

function resgrep()
{
for dir in `find . -name .repo -prune -o -name .git -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
}

function mangrep()
{
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
}

function sepgrep()
{
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@"
}

function allgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.java' -o -name 'AndroidManifest.xml' -o -name '*.xml' -o -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep --color -n "$@"
}

2014년 8월 4일 월요일

Android Studio 오류 해결 Tip



1. Android Studio 설치후 실행시 아래와 같은 에러 발생시


환경설정의 JAVA_HOME 확인후 이상없을 경우는 vmoptions 변경.

Failed to create JVM: error code -4
JVM Path: C:\Program Files\Java\jdk1.7.0_45\jre
If you already have a 32-bit JDK installed, define a JAVA_HOME variable in Computer > System Properties > System Settings > Environment Variables.

C:\Program Files\Android\android-studio\bin\studio.exe.vmoptions
위 파일의 내용을 아래와 같이 변경.
-Xmx512m  -> 256m
-XX:MaxPermSize=250m  -> 128m

2. 윈도우 xp 에서 실행시 splash 이미지만 뜬후 실행되지 않을경우

(특히 android studio update 이후 발생)
vmoptions 수정

-Xms256m -> -Xmx256m
-Xms750m -> -Xmx256m

3. Design Preview 로딩중 상태에서 멈출 경우

clean - rebuild - Invalidate Cacheds/Restart 실행

4. Android ClassNotFoundException: Didn't find class "class name" on path ~ 오류

이미 설치되어 있는 aosp 를 reinstall 할때 주로 발생하였다.
build.gradle 에 "multiDexEnabled true" 로 되어 있는지 확인
없다면, false 로 명시해주자.
보통은 multiDex 관련 에러이나, 다른 원인에 의해 발생할수도 있는것 같다.


5. xml 상에서 "cannot find symbol ?attr/actionBarSize" 등의 오류 발생 (빌드는 잘됨)
  1) close project -> 새로 import projcet 해라
  2) 1 을 해서 안된다면, gradlew cleanBuildCache 해보자
  3) 2 를 해서 안된다면, buildtoolvesion 과 support library 를 최신으로 설정


Android Jetpack viewpager2

  Android Jetpack ViewPager2 기본 개념 및 샘플 코드 오늘은 안드로이드 개발에 있어서 굉장히 유용한 컴포넌트 중 하나인 ViewPager2에 대해 이야기해볼까 합니다. ViewPager2는 사용자 인터페이스에서 여러 화면을 좌우...