2014年11月4日 星期二

ApplicationId

新的 build 系統加了 applicationId 這東西

link

簡單的說, 他要解決不同版本 (free/pro) 如何產出 apk 的問題

例如說兩個版本

  • com.example.my.app.free
  • com.example.my.app.pro

在舊的 build tool 上, 要把 AndroidManifest.xml 分別用不用的 packageName 分開
… 想到就很痛苦

新的 build 系統讓 source code 幾乎都不改的情形下
只修改 .gradle 檔

app/build.gradle:

productFlavors {
    pro {
        applicationId = "com.example.my.pkg.pro"
    }
    free {
        applicationId = "com.example.my.pkg.free"
    }
}
buildTypes {
    debug {
        applicationIdSuffix ".debug"
    }
}
....

注意的點在於,雖然不用改 manifest 裡的 pkg name
可是實際上 package name 已經改了

$ aapt d badging app-release.apk
package: name='com.example.my.pkg.free' versionCode='1' versionName='1.0' platformBuildVersionName=''
sdkVersion:'15'
targetSdkVersion:'20'

如果是直接指定 component 的情形下,要小心

adb shell am start -n com.example.my.pkg/.MainActivity 已經無法使用

要改成

adb shell am start -n com.example.my.pkg.free/com.example.my.pkg.MainActivity

2014年9月23日 星期二

use private API in gradle

build.gradle

加入

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xbootclasspath/p:$projectDir/libs/hidden.jar:$projectDir/libs/hidden2.jar"
        }
    }
}

Gradle duplicated resource error

BSP 在 resource 會使用 product="XXXX" 去分別不同的 target
例如 phone / tablet

在 Eclipse 時代還相安無事
可是 gradle 根本沒有考慮這個情形
(看了一下 source code, 大概吧?)

註: Merge resource check

regex saved my life again !

find res/ -name strings.xml | xargs -n 1 sed -i "" -E '/product="tablet"/d'

2014年8月18日 星期一

Respect View.isInEditMode()

Android 的 layout renderer 並沒有聰明到可以自動去取消每一個 runtime 的程式碼

所以很多時候 onFinishLayout() 裡,onAttachToWindow() 裡
常會有一些 runtime 才會拿得到的東西
這會造成 layout renderer 直接死給你看

解法很簡單
用 isInEditMode() 去把這些 renderer 無法處理的東西包起來
(或者是直接 early return)

或者是之前講的這個...要在 renderer 裡顯示沒有的東西 View.isInEditMode()

很遺憾的是...連 Google 自己都不鳥這個 =__=

2014年8月4日 星期一

early return

看到 BSP 裡不知道在修啥 bug, 把 aosp 原來的 code wrap 了一個 null check 本來可以寫成 early return 結果硬要用 if-else 包起來

private int getWidgetPosition(int id) {
    if (mAppWidgetContainer != null) {
                 // 原來的 code
    } else {
        return -1;
    }
}

一般的 git show or diff 跑出洋洋灑灑的一大片無意義的的畫面 雖然可以下參數避掉, 不過一般還是會用 raw diff 看有沒有多的垃圾

整排indent 的結果 造成整個 diff 多了十行 每次看到這種 code 一整個想翻桌

2014年6月12日 星期四

MacOS skype input lag

自從不知道哪個版本後 Skype 沒事打字就會頓 之前試過只留 main log 再蓋回去有效 可是過陣子又會爛 剛生氣又找了一下,發現這個方法 感覺有效...也沒有之前那麼麻煩
  • Quit Skype
  • rm -rf ~/Library/Caches/com.skype.skype
http://community.skype.com/t5/Mac/Skype-increasing-lagging-and-using-too-much-CPU/td-p/2011405

Fuck you Microsoft

2014年1月8日 星期三

不小心 git commit --amend 了別人的 patch

環境

2d14654 HEAD@{0}: commit (amend): Other's patch
428555b HEAD@{1}: commit: Other's patch
bd33767 HEAD@{2}: commit: Previous one

先把 HEAD 退回到原來的 patch, 記得確定把你的 working directory 搞乾淨

$ git reset --hard HEAD~1
HEAD is now at bd33767 Previous one

$ git cherry-pick 428555b
....

把 amend 到別人 patch 的內容 diff 出來,重新 apply, apply 的參數 - (dash) 表示是從 STDIN 讀入

$ git diff 428555b 2d14654 | git apply -

這時打 git status 就可以發現當初的修改回來 unstage 的狀態了, 重新 git commit

$ git commit

完成

2013年11月26日 星期二

Nexus 5 w/ AOSP

Tested in KRT16M / KOT49H

Steps

Follow the steps here

http://source.android.com/source/building.html

  • unlock device
  • get source code Version

    • KRT16M | android-4.4_r1
    • KOT49H | android-4.4.2_r1
  • get nexus driver

  • fix what's missing in nexus driver

    link
    yes, pull the binary from stock ROM first If you didn't do that, your SIM cannot be used

  • (optional) get /system/media/bootanimation.zip Because AOSP android doesn't have nexus animation

  • (ADD: 2013/11/29 16:55) add Network Location Provider for GMS
    link
    Fixed Wireless GPS issues. Changed "config_locationProviderPackageNames" from "com.google.android.location" to "com.google.android.gms" in frameworks/base/core/res/res/values/config.xml

  • start to build

      $ source build/envsetup.sh  
      $ lunch  
          => Press AOSP hammerhead userdebug  
      $ make clobber  
      $ make -j 4  
    
  • flash custom recovery (CWM or TWRP)

  • flash everything other than recovery

  • fastboot reboot bootloader

  • Press VOL-UP than power button to enter recovery mode
    Choose Advanced -> sideload mode, if you are using TWRP

      $ adb sideload gapps
          gapps link http://forum.xda-developers.com/showthread.php?t=2397942
      $ adb sideload stock_boot_animation or 
          adb push bootanimation.zip into /system/media/bootanimation.zip
    
  • do a factory reset

  • (ADD: 2013/12/19 16:07)
    fix green line issue in camcorder KOT49H (KRT16M has this issue?)
    Replace /system/lib/libmmcamera_interface.so by stock one
    link

Have fun!

2013年11月12日 星期二

WeakReference listener in API

在找 OnSharedPreferenceChangeListener 範例抄時找到這個

SharedPreferences keeps listeners in a WeakHashMap. This means that you cannot use an anonymous inner class as a listener, as it will become the target of garbage collection as soon as you leave the current scope.

SharedPreferences.onSharedPreferenceChangeListener not being called consistently

靠... 這很容易踩到啊 =_=

2013年11月2日 星期六

ad block on android

plurka 廣告設計得太爛,不要怪我對你不義啊

記錄一下

adb shell mount -o rw,remount /system 
adb push hosts.for.mobile.txt /etc/hosts
adb reboot

refs: xda