2015-12-25

Facebook BUCK with multidex

程式開發後期通常會遇見 Building Apps with over 65k methods 的問題,底下是利用 BUCK 執行編譯時遇到此問題的解決方法 (啟用 multidex 功能之設定檔的筆記) 。

BUCK :
...

# setup multidex jar
prebuilt_jar(
  name = 'support_multidex',
  binary_jar = 'com.android.support/multidex/1.0.0/jars/classes.jar',
  visibility = ['PUBLIC']
)

...

# include multidex jar
android_library(
  name = 'lib',
  srcs = glob(['src/**/*.java',...]),
  deps = [
    ':support_multidex',
    ...
  ],
  visibility = ['PUBLIC'],
)

...

# build apk with multidex
android_binary(
  name = 'release',
  manifest = 'AndroidManifest.xml',
  use_split_dex = True,
  deps = [':lib'],
  package_type='release',
  ...
)

...


AndroidManifest (在 application tag 設定 android:name 屬性) :
<?xml version="1.0" encoding="utf-8"?>
<manifest 
  ... >
  <application 
    android:name="com.mypackage.name.App"
    ...>

    ...

  </application>
</manifest>
新增 App.java :
package com.mypackage.name;
public class App extends android.support.multidex.MultiDexApplication{
}