Friday, October 14, 2011

一個Eclipse匯入Android變紅XX的錯誤

案子在匯入後會變成紅色方型XX,
有非常多的理由。
通常我們都要在第1時間去看Console視窗裡寫些什麼錯誤訊息。


今天在匯入案子進筆電時,
發生了一個錯誤︰

[2011-10-15 14:25:00 - JeremyLiu] Dx
trouble processing "java/nio/CharBuffer.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.

[2011-10-15 14:25:00 - JeremyLiu] Dx 1 error; aborting
[2011-10-15 14:25:00 - JeremyLiu] Conversion to Dalvik format failed with error 1

後來查了一下國外的論壇,才發現是專案在匯入Android的Jar檔時,Library Build錯位置了。

整個關鍵在於︰

 解決方式︰
Library標籤下應該會有一個android.jar(沒有放在Android2.2目錄下) ,
將其刪除,
並再將Android2.2Library匯入即可。





Wednesday, October 12, 2011

作品上新聞了

前一陣子接了一個外部合作案,
是三商美邦的「樂減碳小幫手」。

本來一開始是覺得產品規格不算多,
所以邊做邊重構。

但做到最後一天,
由於資料庫還不太熟,
加上伺服器端的程式又一直在修改,
一直熬夜到早上五點才完成這個案子。

不過看到新聞稿還蠻開心的。(笑)



相關連結︰

三商美邦人壽 綠色保險計劃探訪台灣人碳足跡

全台首創APP 保護地球少碳氣

三商美邦人壽啟動綠色保險計畫

三商美邦人壽推APP碳足跡記錄器

調查/台灣每人每日碳足跡19.6公斤 主管比職員多25%

減少碳排量 從日常生活做起

台灣人每天排碳19.6公斤 超過聯合國標準4倍

 

使用Proguard和Vpon時廣告出不來

今天遇見一個技術問題︰

即使在已匯入Vpon JAR檔的狀況下,
在做Proguard(程式碼模糊混淆)產出程式,
Vpon仍會顯示沒有正確的Adapter接收廣告
造成廣告無法正常顯示的問題。

出錯的LOG如下︰

Caught an exception in adapter:
java.lang.Exception: Invalid adapter
    at com.adwhirl.a.a.a(Unknown Source)
    at com.adwhirl.AdWhirlLayout.d(Unknown Source)
    at com.adwhirl.b.run(Unknown Source)

這個問題後來我發現︰
如果直接使用debug模式輸出程式時,
Vpon廣告是能顯示的。
原來是被Proguard混淆時,
打亂了廣告接收器(Adapter)。

解決方法︰
在Proguard腳本(proguard.cfg)中加入以下程式碼
-dontwarn com.vpon.**
-dontwarn javadoc.**
-dontwarn properties.**
-dontwarn com.adwhirl.**
-keep class com.vpon.** { *; }
-keep class javadoc.** { *; }
-keep class properties.** { *; }
-keep class com.adwhirl.** { *; }
 

上面這些是adOn.jar和adwhirl.jar裡所有的套件名稱,
在劇本裡下這些指令就能跳過混淆這2組jar檔,
讓廣告順利產出。

相關文章︰


Facebook.authroize()認證一片空白的問題

今天在做Facebook.authroize()時,
要驗証時一直出現全空白的畫面,
然後告訴我︰連結的(FB)應用程式出錯,
導致一直無法正常登入FB。

後來發現這是Facebook SSO(Single-Sign-On)單一登入機制的問題,
只要在程式碼中加入強制另外登入機制即可。

facebook.authorize(Activity, new String[] {"publish_stream" },Facebook.FORCE_DIALOG_AUTH,
        new Facebook.DialogListener() {});

這樣子Facebook就不會在你的應用程式被後跑SSO機制,
導制認證出錯了。

Tuesday, October 11, 2011

感謝大家對我第1隻程式︰統一發票愛我的支持

今天蠻感動的,
雖然這是技術論壇,
但我覺得還是可以把一點點心情寫在這裡。
因為布落格是我的。
XD

Android的硬體規格問題,
雖然在開發過程中我罵歸罵,
但是今天又收到使用者寄信來問我為什麼找不到我之前開發的
「統一發票愛我」?
(因為已經陸續收到7封信了。)
這隻程式半年累計1萬下載人次,100人4.5顆星以上好評果真不是蓋的

這隻程式因為版權是前公司所有,
所以我已經不方便更新和維護了。

但當收到大家對這隻程式的關心和詢問,
我想我當初絞盡腦汁的用心,
使用者真的感受到了。