The self-signed certificate used to sign your application in debug mode (the default on Eclipse/ADT and Ant builds) will have an expiration date of 365 days from its creation date.
When the certificate expires, you will get a build error. On Ant builds, the error looks like this:
debug: [echo]Packaging bin/samples-debug.apk,and signing it with a debug key... [exec]DebugCertificate expired on 8/4/083:43 PM
In Eclipse/ADT, you will see a similar error in the Android console.
To fix this problem, simply delete the debug.keystore file. The default storage location for AVDs is in ~/.android/ on OS X and Linux, in C:\Documents and Settings\\.android\ on Windows XP, and in C:\Users\\.android\ on Windows Vista.
The next time you build, the build tools will regenerate a new keystore and debug key.
Note that, if your development machine is using a non-Gregorian locale, the build tools may erroneously generate an already-expired debug certificate, so that you get an error when trying to compile your application. For workaround information, see the troubleshooting topic I can't compile my app because the build tools generated an expired debug certificate.
I can't compile my app because the build tools generated an expired debug certificate
If your development machine uses a locale that has a non-Gregorian calendar, you may encounter problems when first trying to compile and run your application. Specifically, you may find that the Android build tools won't compile your application because the debug key is expired.
The problem occurs because the Keytool utility — included in the JDK and used by the Android build tools — fails to properly handle non-Gregorian locales and may create validity dates that are in the past. That is, it may generate a debug key that is already expired, which results in the compile error.
If you encounter this problem, follow these steps to work around it:
First, delete the debug keystore/key already generated by the Android build tools. Specifically, delete thedebug.keystore file. On Linux/Mac OSX, the file is stored in ~/.android. On Windows XP, the file is stored inC:\Documents and Settings\<user>\.android. On Windows Vista, the file is stored in C:\Users\<user>\.android
Next, you can either
Temporarily change your development machine's locale (date and time) to one that uses a Gregorian calendar, for example, United States. Once the locale is changed, use the Android build tools to compile and install your app. The build tools will regenerate a new keystore and debug key with valid dates. Once the new debug key is generated, you can reset your development machine to the original locale.
Alternatively, if you do not want to change your machine's locale settings, you can generate the keystore/key on any machine using the Gregorian calendar, then copy the debug.keystore file from that computer to the proper location on your development machine.
This problem has been verified on Windows and may apply to other platforms.
Android application 은 xml 파일을 작성하여 UI layout을 생성할 수 있다.
이 UI layout을 위한 xml파일이 효율적으로 작성이 되어 있는지를 검사해주는 툴이 layoutopt 이다.
사용 법은 간단하다.
usage: layoutopt <directories/files to analyze>
$ layoutopt samples/samples/compound.xml
7:23 The root-level <FrameLayout/> can be replaced with <merge/>
11:21 This LinearLayout layout or its FrameLayout parent is useless samples/simple.xml
7:7 The root-level <FrameLayout/> can be replaced with <merge/>
samples/too_deep.xml
-1:-1 This layout has too many nested layouts: 13 levels, it should have <= 10!
20:81 This LinearLayout layout or its LinearLayout parent is useless
24:79 This LinearLayout layout or its LinearLayout parent is useless
28:77 This LinearLayout layout or its LinearLayout parent is useless
32:75 This LinearLayout layout or its LinearLayout parent is useless
36:73 This LinearLayout layout or its LinearLayout parent is useless
40:71 This LinearLayout layout or its LinearLayout parent is useless
44:69 This LinearLayout layout or its LinearLayout parent is useless
48:67 This LinearLayout layout or its LinearLayout parent is useless
52:65 This LinearLayout layout or its LinearLayout parent is useless
56:63 This LinearLayout layout or its LinearLayout parent is useless
samples/too_many.xml
7:413 The root-level <FrameLayout/> can be replaced with <merge/>
-1:-1 This layout has too many views: 81 views, it should have <= 80! samples/useless.xml
7:19 The root-level <FrameLayout/> can be replaced with <merge/>
11:17 This LinearLayout layout or its FrameLayout parent is useless
하지만 Window 환경에서 layoutopt를 수정없이 사용하게 되면 아래와 같은 에러를 보게 될 것이다.
Exception in thread "main" java.lang.NoClassDefFoundError: lib\layoutopt/jar
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: lib\layoutopt.jar. Program will exit.
포스팅된 글을 끝까지 잘 읽어보면 해결책이 나와있다.
Windows users: to start layoutopt, open the file called layoutopt.bat in the tools directory of the SDK and on the last line, replace %jarpath% with -jar %jarpath
쉽게 이해가 안되면 아래와 같이 따라하자.
1. \sdk\android-sdk-windows\tools\layoutopt.bat 파일을 편집기로 연다.
2. 파일의 제일 마지막을 다음과 같이 수정한다.
수정 전 call java %java_debug% -Djava.ext.dirs=%javaextdirs% %jarpath% %*
수정 후 call java %java_debug% -Djava.ext.dirs=%javaextdirs% -jar %jarpath% %*
3. 파일을 저장 후 layoutopt를 사용한다.
파일명을 직접 입력 하거나, xml 파일이 있는 폴더명을 입력해주면 해당 폴더 내의 모든 xml 파일을 분석한다.
분석 내용이 길어질 경우를 대비에 > 를 사용해 출력을 analyze.txt에 담아도 좋다.