HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2011/04/10

Google Android開発環境の構築 SDK r10版 Google Android開発環境の構築 SDK r10版

(SDK r8から Java難読化&最適化の ProGuardが標準装備されました。(最新のSDK r10版に対応))

Tags: [Android開発]




●Android SDK r8 メモ

 Android SDK r8から ProGuardが標準装備されました。

 ProGuardとは、Javaのプログラムを
 軽量化、最適化(Optimizer)、難読化(Obfuscator)するものです。
 主にリバースエンジニアリングを困難にする目的で使われます。

●ProGuard Java Optimizer and Obfuscator
ProGuard Java Optimizer and Obfuscator


●Download the Android SDK
Download the Android SDK

Windows android-sdk_r08-windows.zip
Windows android-sdk_r08-windows.zip


●Download the Android NDK
Download the Android NDK

Windows
android-ndk-r5-windows.zip
62217450 bytes
59cbb02d91d74e9c5c7278d94c989e80
Windows android-ndk-r5-windows.zip


●Apache Ant
Apache Ant

Binary Distributions
apache-ant-1.8.2-bin.zip
apache-ant-1.8.2-bin.zip

●Java SDK
Windows x86 76.81 MB jdk-6u29-windows-i586.exe
2011/10 Java SE Development Kit 6 Update 29


・Android SDK r8の開発環境の構築
Android SDK r8の開発環境の構築




●ProGuardを有効にする方法

 プロジェクトのディレクトリの
default.properties
 に
proguard.config=proguard.cfg
 を追加する。

 例:default.propertiesファイル
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-4
proguard.config=proguard.cfg


 ProGuardを使用しているときのコンパイル途中の表示

-obfuscate:
    [mkdir] Created dir: D:\Android\Project\ProGuardTest\bin\proguard
      [jar] Building jar: D:\Android\Project\ProGuardTest\bin\proguard\original.jar
 [proguard] ProGuard, version 4.4
 [proguard] ProGuard is released under the GNU General Public License. The autho
rs of all
 [proguard] programs or plugins that link to it (com.android.ant, ...) therefore

 [proguard] must ensure that these programs carry the GNU General Public License
 as well.
 [proguard] Reading input...

 ~~ 省略 ~~



●ProGuardの生成ファイル

{Project-Directory}\bin\proguard
 に
dump.txt
mapping.txt
obfuscated.jar
original.jar
seeds.txt
usage.txt
 のファイルができます。

 このうち、
mapping.txt
 は、難読化されたスタックトレースをデコードするのに必要となります。

 retrace.batコマンドを使います。

 retrace.batコマンド
ProGuard Decoding Obfuscated Stack Traces
ProGuard Decoding Obfuscated Stack Traces

retrace.bat [-verbose] mapping.txt [<stacktrace_file>]



●Android SDK r8 メモ2( Androidの コンパイルを UTF-8対応にする方法。)

 Androidの Javaのソースリストに日本語を含む場合、Antでコンパイルでエラーが出る。

 Antの定義ファイルの文字エンコード指定が Asciiになっている所為です。
 ※ いいかげんデフォルト UTF-8の状態で配布しろよ。
 ※ Android SDK r9からデフォルトで UTF-8の状態になりました。

[javac] D:\Android\Project\hello\src\com\example\hello\Hello.java:**:
警告: この文字は、エンコーディング ascii にマップできません。


150行目を変更
D:\Android\android-sdk\tools\ant
 の
lib_rules.xml
 の encoding="ascii"を encoding="utf-8"に書き換える。
        <javac encoding="utf-8" target="1.5" debug="true" extdirs=""
                destdir="${out.classes.absolute.dir}"
                bootclasspathref="android.target.classpath"


121行目を変更
D:\Android\android-sdk\tools\ant
 の
main_rules.xml
 の value="ascii"を value="utf-8"に書き換える。
    <!-- compilation options -->
    <property name="java.encoding" value="utf-8" />
    <property name="java.target" value="1.5" />
    <property name="java.source" value="1.5" />


 さらに、下記の警告が出る場合は
 ※ Android SDK r9 / Android SDK r10でもこの警告は出ます。

compile:
    [javac] D:\Android\android-sdk\tools\ant\main_rules.xml:361:
      warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last;
        set to false for repeatable builds

355行目に追加
 includeAntRuntime="true"を追加する。
    



●Android SDK r12以降で発生?

No resource found @android:style/WindowTitle
No resource found @android:style/WindowTitleBackground
 等のエラーが発生する。

 エラーの症状
[aapt.exe] hoge\res\values\styles.xml:123: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Widget.TextView.ListSeparator'.
[aapt.exe] hoge\res\values\styles.xml:234: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/WindowTitle'.
[aapt.exe] hoge\res\values\styles.xml:345: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/WindowTitleBackground'.
 原因
 "@android:style/~"の幾つかが使用禁止になったため。

 回避方法
"@android:style/WindowTitle"
 を
"@*android:style/WindowTitle"
 にする。



●AdSenseを組み込んでいると ProGuardでエラーが出る。

AdSense AFMAUtil ProGuard Exception = [java.lang.ArrayIndexOutOfBoundsException]

 エラーの内容
 [proguard] ProGuard, version 4.4
 [proguard] ProGuard is released under the GNU General Public License. The authors of all
 [proguard] programs or plugins that link to it (com.android.ant, ...) therefore
 [proguard] must ensure that these programs carry the GNU General Public License as well.
 [proguard] Reading input...
 [proguard] Initializing...
 [proguard] Note: com.google.ads.AFMAUtil:
   can't find dynamically referenced class android.os.SystemProperties
 [proguard] Note: com.google.ads.AFMAUtil accesses a declared method
   'get(java.lang.String)' dynamically
 [proguard]       Maybe this is library method
   'android.content.ContentValues {java.lang.Object get(java.lang.String); }'
 [proguard]       Maybe this is library method
   'android.hardware.Camera$Parameters { java.lang.String get(java.lang.String); }'
 [proguard]       Maybe this is library method
   'android.os.Bundle { java.lang.Object get(java.lang.String); }'

 ~~ 省略 ~~

 [proguard] Note: there were 1 accesses to class members by means of introspection.
 [proguard]       You should consider explicitly keeping the mentioned class members
 [proguard]       (using '-keep' or '-keepclassmembers').
 [proguard] Ignoring unused library classes...
 [proguard]   Original number of library classes: 2400
 [proguard]   Final number of library classes:    387
 [proguard] Printing kept classes, fields, and methods...
 [proguard] Shrinking...
 [proguard] Printing usage to [D:\Android\Project\XXX\\bin\proguard\usage.txt]...
 [proguard] Removing unused program classes and class elements...
 [proguard]   Original number of program classes: 91
 [proguard]   Final number of program classes:    66
 [proguard] Optimizing...
 [proguard] Unexpected error while performing partial evaluation:
 [proguard]   Class       = [com/google/ads/AFMAUtil]
 [proguard]   Method      = [c([B[B)[B]
 [proguard]   Exception   = [java.lang.ArrayIndexOutOfBoundsException] (-1)

BUILD FAILED
D:\Android\android-sdk\tools\ant\main_rules.xml:431:
  java.lang.ArrayIndexOutOfBoundsException: -1
        at proguard.optimize.peephole.BranchTargetFinder.visitConstantInstruction
          (BranchTargetFinder.java:496)


 解決方法
proguard.cfg
 に
-dontoptimize
 を追加する。

 ※ -keep 指定で行けそうな気がするが、指定方法が分からない。

 元の proguard.cfgのファイルはここにある。
D:\Android\android-sdk\tools\lib

proguard.cfg
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService

 ~~ 省略 ~~

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-dontoptimize




●strings.xmlで error: Error parsing XML: not well-formed (invalid token)

[aapt.exe] hoge_project\res\values\strings.xml:xx: error: Error parsing XML: not well-formed (invalid token)

formatted="false"を追加

<string name="hoge_string" formatted="false">Hoge String(s)</string>



●AdMobを組み込んで ProGuard最適化すると実行時に「予期せず停止しました」のエラーが出る。

※ この情報は2011/4以降の新バージョンの AdMobです。

 ProGuard AdMob InflateException LayoutInflater com.google.ads.GoogleAdView

 解決方法
proguard.cfg
 に
-keep public class com.google.ads.GoogleAdView
 を追加する。


●AdMobを組み込んで ProGuard最適化すると実行時に「予期せず停止しました」のエラーが出る。

※ この情報は旧バージョンの AdMobです。

 ProGuard AdMob InflateException LayoutInflater com.admob.android.ads.AdView

 解決方法
proguard.cfg
 に
-keep public class com.admob.android.ads.AdView
 を追加する。

ProGuardでの AdMobのエラーログ
ERROR/AndroidRuntime(993): java.lang.RuntimeException:
 Unable to start activity ComponentInfo
  {jp.ne.neko.freewing.xxx/jp.ne.neko.freewing.xxx}:
   android.view.InflateException: Binary XML file line #32:
    Error inflating class com.admob.android.ads.AdView
ERROR/AndroidRuntime(993):
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2705)
ERROR/AndroidRuntime(993):
 Caused by: android.view.InflateException:
  Binary XML file line #32: Error inflating class com.admob.android.ads.AdView
ERROR/AndroidRuntime(993):
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)




●俺メモ

import android.os.Build.VERSION_CODES

Build.VERSION_CODES

if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.FROYO)
{
Eclair以下の処理
}


1 int BASE October 2008: The original, first, version of Android.
2 int BASE_1_1 February 2009: First Android update, officially called 1.1.

--- 壁 --- 1.5
3 int CUPCAKE May 2009: Android 1.5.

--- 壁 --- 1.6
4 int DONUT September 2009: Android 1.6.

--- 壁 --- 2.0
5 int ECLAIR November 2009: Android 2.0
Applications targeting this or a later release will get these new changes in behavior
6 int ECLAIR_0_1 December 2009: Android 2.0.1

--- 壁 --- 2.1
7 int ECLAIR_MR1 January 2010: Android 2.1

--- 壁 --- 2.2
8 int FROYO June 2010: Android 2.2

--- 壁 --- 2.3
9 int GINGERBREAD November 2010: Android 2.3
10 int GINGERBREAD_MR1 February 2011: Android 2.3.3.

--- 壁 --- 3.0
11 int HONEYCOMB February 2011: Android 3.0.
12 int HONEYCOMB_MR1 May 2011: Android 3.1.
13 int HONEYCOMB_MR2 June 2011: Android 3.2.

--- 壁 --- 4.0
14 Android 4.0.1 4.0.2 Ice Cream Sandwich
15 Android 4.0.3 Ice Cream Sandwich

--- 番外 ---
10000 int CUR_DEVELOPMENT Magic version number for a current development build, which has not yet turned into an official release.


http://source.android.com/source/build-numbers.html

Code name Version API level
(no code name) 1.0 API level 1
(no code name) 1.1 API level 2
Cupcake 1.5 API level 3, NDK 1
Donut 1.6 API level 4, NDK 2
Eclair 2.0 API level 5
Eclair 2.0.1 API level 6
Eclair 2.1 API level 7, NDK 3
Froyo 2.2.x API level 8, NDK 4
Gingerbread 2.3 - 2.3.2 API level 9, NDK 5
Gingerbread 2.3.3 - 2.3.7 API level 10
Honeycomb 3.0 API level 11
Honeycomb 3.1 API level 12, NDK 6
Honeycomb 3.2.x API level 13
IceCreamSandwich 4.0.1 - 4.0.2 API level 14, NDK 7
IceCreamSandwich 4.0.3 API level 15

--

Build Tag Notes
DRC83 android-1.6_r1.1 earliest Donut version, ADP1, ADP2
DRC92 android-1.6_r1.2
DRD08 android-1.6_r1.3
DRD20 android-1.6_r1.4
DMD64 android-1.6_r1.5 latest Donut version
ESD20 android-2.0_r1 earliest Eclair version
ESD56 android-2.0.1_r1
ERD79 android-2.1_r1 Nexus One
ERE27 android-2.1_r2 Nexus One
EPE54B android-2.1_r2.1p Nexus One
ESE81 android-2.1_r2.1s
EPF21B android-2.1_r2.1p2 latest Eclair version
FRF85B android-2.2_r1 earliest Froyo version, Nexus One
FRF91 android-2.2_r1.1 Nexus One
FRG01B android-2.2_r1.2
FRG22D android-2.2_r1.3
FRG83 android-2.2.1_r1 Nexus One
FRG83D android-2.2.1_r2 Nexus One
FRG83G android-2.2.2_r1 Nexus One
FRK76 android-2.2.3_r1
FRK76C android-2.2.3_r2 latest Froyo version
GRH55 android-2.3_r1 earliest Gingerbread version, Nexus S
GRH78 android-2.3.1_r1 Nexus S
GRH78C android-2.3.2_r1 Nexus S
GRI40 android-2.3.3_r1 Nexus One, Nexus S
GRI54 android-2.3.3_r1.1 Nexus S
GRJ06D android-2.3.4_r0.9 Nexus S 4G
GRJ22 android-2.3.4_r1 Nexus One, Nexus S, Nexus S 4G
GRJ90 android-2.3.5_r1 Nexus S 4G
GRK39C android-2.3.6_r0.9 Nexus S
GRK39F android-2.3.6_r1 Nexus One, Nexus S
GWK74 android-2.3.7_r1 latest Gingerbread version, Nexus S 4G
ITL41D android-4.0.1_r1 earliest IceCreamSandwich version, Galaxy Nexus
ITL41D android-4.0.1_r1.1 Galaxy Nexus
ITL41F android-4.0.1_r1.2 Galaxy Nexus
ICL53F android-4.0.2_r1 Galaxy Nexus
IML74K android-4.0.3_r1 Nexus S
IML77 latest IceCreamSandwich version



●俺メモ

 Android Source Code GitHub
https://github.com/OESF/

 OHA-Android-2.3.4_r1.0
https://github.com/OESF/OHA-Android-2.3.4_r1.0.git
 OHA-Android-2.3.4_r1.0.zip
https://github.com/OESF/OHA-Android-2.3.4_r1.0/zipball/master



●俺メモ
 [Windows XP/VISTA/7][UTILITY][TOOL] APK Multi-Tool
http://forum.xda-developers.com/showthread.php?t=1310151

[Windows XP/VISTA/7][UTILITY][TOOL] APK Multi-Tool
I am currently working on a major update to the apk manager application as well and changing the name to APK Multi-Tool with some new added features and also to fix some issues with some code errors.


 ApkMultiTools (APK Multi-Tools)
https://github.com/ApkMultiTools

 build/tools/signapk/SignApk.java
 out/host/linux-x86/framework/signapk.jar

http://code.google.com/p/android-apktool/downloads/list




Tags: [Android開発]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

Google Android開発環境の構築のつもり
Google Android開発環境の構築のつもり

  Eclipse重い重い! Javaって相変わらずクソ重いね!

Google Android JNI NDKの C/C++言語開発環境の構築のつもり
Google Android JNI NDKの C/C++言語開発環境の構築のつもり

  Android JNI NDKで C言語の Native関数を作って処理速度を高速化

au IS01(SHARP)アンドロイド端末で開発
au IS01(SHARP)アンドロイド端末で開発

  SHARPの Android端末 IS01で開発

au IS01(SHARP)アンドロイド端末で遊ぼう
au IS01(SHARP)アンドロイド端末で遊ぼう

  SHARPの Android端末 IS01の便利な設定や使い方

Android WiFi On/Off Toggle switcher
Android WiFi On/Off Toggle switcher

  WiFiのON/OFFを交互に切り替えの簡単操作の便利ツール




[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2011 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/android/android_sdk_r8/