SlideShare a Scribd company logo
1 of 12
Android Dynamic Module
Lập trình module động trong Android
Phí Ngọc Chi – CTO Eway JSC
chipn@eway.vn | facebook.com/phingocchi
Cập nhật Ứng Dụng Android
APK

APK

Module v 2.0

Module v 1.0

…

…

…

…

,,,

…

Server

Client
Cập nhật Module
APK
APK
Module v 2.0

Module v 1.0
…
…
…

Server

Client
Ưu điểm cập nhật theo Module
Mềm dẻo và linh động
 Khả năng mở rộng tốt
 Đơn giản hóa việc cập nhật với người dùng
 Dung lượng cập nhật nhỏ
 Tốc độ cập nhật nhanh tức thời

Dynamic Module



Module được phát triển như một project độc
lập và đóng gói thành file module.apk
Ứng dụng chính tải file module.apk từ URL



DexClassLoader: thư viện sử dụng để nạp class
động từ file module.apk



Java Reflection: khởi tạo object từ class động
và tương tác với object để kích hoạt logic thực
thi
Module.apk – v2.0

Module
…

Download Module

Load Module

DexClassLoader

APK

Module.apk – v1.0

Java Reflection

Quy trình cập nhật Module

Load Module Class

New Instance
Invoke Method

Active Module
DemoModule Code
public class DemoModule {
public void show() {

Toast.makeText(getApplicationContext(), "Hi!
version 1.0", Toast.LENGTH_SHORT).show();
}
}

DemoModule.apk - v1.0

public class DemoModule{
public void show() {
AlertDialog dialog = new
AlertDialog.Builder(this).create();
dialog.setMessage("Hi! version 2.0");
dialog.show();
}
}

DemoModule.apk – v2.0
Download DemoModule
public void downloadDemoModule(Context context) {
String dexPath = new File(context.getDir("dex",
Context.MODE_PRIVATE), "DemoModule.apk").getAbsolutePath();

//TODO: download DemoModule.apk from URL to dexPath File
}
Load DemoModule
public DexClassLoader getDemoModuleClassLoader(Context context) {
String dexPath = new File(context.getDir("dex",
Context.MODE_PRIVATE), "DemoModule.apk").getAbsolutePath();
String optimizedDirectory = context.getDir("temp", 0).toString();
String libraryPath = null;
ClassLoader parent ClassLoader = context.getClassLoader();
DexClassLoader dexClassLoader = new DexClassLoader(dexPath,
optimizedDirectory, libraryPath, parentClassLoader);
return dexClassLoader;
}
Active DemoModule
DexClassLoader classLoader = this.getDemoModuleClassLoader(this);
try {
Class<?> demoModuleClass =
classLoader.loadClass("com.simple.DemoModule");
Object demoModule = demoModuleClass.newInstance();
demoModuleClass.getMethod("show").invoke(demoModule);
} catch (Exception ex) {
ex.printStackTrace();
}
DemoModule Screenshot
Thanks for your attention!
Phí Ngọc Chi – CTO Eway JSC
chipn@eway.vn | facebook.com/phingocchi

More Related Content

Viewers also liked

Ch13 system testexecution
Ch13 system testexecutionCh13 system testexecution
Ch13 system testexecutionabcxyz_abc
 
Resumes: Remove the Irrelevant
Resumes: Remove the IrrelevantResumes: Remove the Irrelevant
Resumes: Remove the IrrelevantSteve Rogers
 
Wisdom From A Laugh 57, 58
Wisdom From A Laugh 57, 58Wisdom From A Laugh 57, 58
Wisdom From A Laugh 57, 58OH TEIK BIN
 
Unit 9 photography techniques iuuo
Unit 9   photography techniques iuuoUnit 9   photography techniques iuuo
Unit 9 photography techniques iuuoliamwhitemtb
 
Reference: Mobile payment industry in china 2012-2015
Reference: Mobile payment industry in china 2012-2015 Reference: Mobile payment industry in china 2012-2015
Reference: Mobile payment industry in china 2012-2015 C. Keiko Funahashi
 
Me in china daily 30.12.2012
Me in china daily 30.12.2012Me in china daily 30.12.2012
Me in china daily 30.12.2012Mark Henderson
 
Databazove systemy6
Databazove systemy6Databazove systemy6
Databazove systemy6olc_user
 
Google搜索从入门到精通v40
Google搜索从入门到精通v40Google搜索从入门到精通v40
Google搜索从入门到精通v40静 黄
 
Palestra cheng nutrition
Palestra cheng nutritionPalestra cheng nutrition
Palestra cheng nutritionfruticultura
 

Viewers also liked (15)

DGAE
DGAEDGAE
DGAE
 
Ch13 system testexecution
Ch13 system testexecutionCh13 system testexecution
Ch13 system testexecution
 
Resumes: Remove the Irrelevant
Resumes: Remove the IrrelevantResumes: Remove the Irrelevant
Resumes: Remove the Irrelevant
 
Wisdom From A Laugh 57, 58
Wisdom From A Laugh 57, 58Wisdom From A Laugh 57, 58
Wisdom From A Laugh 57, 58
 
Sujal enterprise
Sujal enterpriseSujal enterprise
Sujal enterprise
 
Unit 9 photography techniques iuuo
Unit 9   photography techniques iuuoUnit 9   photography techniques iuuo
Unit 9 photography techniques iuuo
 
Reference: Mobile payment industry in china 2012-2015
Reference: Mobile payment industry in china 2012-2015 Reference: Mobile payment industry in china 2012-2015
Reference: Mobile payment industry in china 2012-2015
 
Me in china daily 30.12.2012
Me in china daily 30.12.2012Me in china daily 30.12.2012
Me in china daily 30.12.2012
 
Elearning v.0.0
Elearning v.0.0Elearning v.0.0
Elearning v.0.0
 
The Beauty Of The Sea
The Beauty Of The SeaThe Beauty Of The Sea
The Beauty Of The Sea
 
Databazove systemy6
Databazove systemy6Databazove systemy6
Databazove systemy6
 
Monografia 1 ctr
Monografia 1 ctrMonografia 1 ctr
Monografia 1 ctr
 
Google搜索从入门到精通v40
Google搜索从入门到精通v40Google搜索从入门到精通v40
Google搜索从入门到精通v40
 
Attom
AttomAttom
Attom
 
Palestra cheng nutrition
Palestra cheng nutritionPalestra cheng nutrition
Palestra cheng nutrition
 

Similar to Android dynamic module

[Athena] Nguyễn Nhật Nguyên - Báo cáo thực tập
[Athena] Nguyễn Nhật Nguyên - Báo cáo thực tập[Athena] Nguyễn Nhật Nguyên - Báo cáo thực tập
[Athena] Nguyễn Nhật Nguyên - Báo cáo thực tậpnnn4194a
 
Bài 1: Giới thiệu Android
Bài 1: Giới thiệu AndroidBài 1: Giới thiệu Android
Bài 1: Giới thiệu Androidhoccungdoanhnghiep
 
Mixing asp.net mvc & web form into hybrid project
Mixing asp.net mvc & web form into hybrid projectMixing asp.net mvc & web form into hybrid project
Mixing asp.net mvc & web form into hybrid projectMinh Tri Lam
 
Spring framework
Spring frameworkSpring framework
Spring frameworkAn Nguyen
 
Revit API & WPF Training - 15 Lessons | Alpha BIM 2023
Revit API & WPF Training - 15 Lessons | Alpha BIM 2023Revit API & WPF Training - 15 Lessons | Alpha BIM 2023
Revit API & WPF Training - 15 Lessons | Alpha BIM 2023DangLeQuan1
 
Pham Anh Tu - TK Framework
Pham Anh Tu - TK FrameworkPham Anh Tu - TK Framework
Pham Anh Tu - TK FrameworkVu Hung Nguyen
 
Báo cáo thực tập chuyên nghành lập trình Android GPSGroup
Báo cáo thực tập chuyên nghành lập trình Android GPSGroupBáo cáo thực tập chuyên nghành lập trình Android GPSGroup
Báo cáo thực tập chuyên nghành lập trình Android GPSGroupTinh Ngo
 
1 gioithieuveandroidsdk-150322215607-conversion-gate01
1 gioithieuveandroidsdk-150322215607-conversion-gate011 gioithieuveandroidsdk-150322215607-conversion-gate01
1 gioithieuveandroidsdk-150322215607-conversion-gate01Lê Phú Thảo
 
Slide bài giảng lập trình Android DTU - Phần 1
Slide bài giảng lập trình Android DTU - Phần 1Slide bài giảng lập trình Android DTU - Phần 1
Slide bài giảng lập trình Android DTU - Phần 1Techacademy Software
 
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...Ngo Trung
 
429157477-Slide-Bao-Cao.pdf
429157477-Slide-Bao-Cao.pdf429157477-Slide-Bao-Cao.pdf
429157477-Slide-Bao-Cao.pdfToNguyen16
 
Jdeveloper12c
Jdeveloper12cJdeveloper12c
Jdeveloper12cle larry
 
Bài tập Lập trinh viên thiết bị di động
Bài tập Lập trinh viên thiết bị di độngBài tập Lập trinh viên thiết bị di động
Bài tập Lập trinh viên thiết bị di độngRobert Commando
 
01 chuong01tongquanveasp netmvc5
01 chuong01tongquanveasp netmvc501 chuong01tongquanveasp netmvc5
01 chuong01tongquanveasp netmvc5Thanh Nguyen
 
Asp.net mvc framework qua cac vi du
Asp.net mvc framework  qua cac vi duAsp.net mvc framework  qua cac vi du
Asp.net mvc framework qua cac vi duKim Hyun Hai
 
mp_hag_slide_android_2321.pptx
mp_hag_slide_android_2321.pptxmp_hag_slide_android_2321.pptx
mp_hag_slide_android_2321.pptxKhngNguyn81
 
The First 2015 Saigon WordPress Meetup
The First 2015 Saigon WordPress MeetupThe First 2015 Saigon WordPress Meetup
The First 2015 Saigon WordPress MeetupKhanhPham
 
Tim hieugooglecode tortoisesvn
Tim hieugooglecode tortoisesvnTim hieugooglecode tortoisesvn
Tim hieugooglecode tortoisesvnKhong Van Nhat
 

Similar to Android dynamic module (18)

[Athena] Nguyễn Nhật Nguyên - Báo cáo thực tập
[Athena] Nguyễn Nhật Nguyên - Báo cáo thực tập[Athena] Nguyễn Nhật Nguyên - Báo cáo thực tập
[Athena] Nguyễn Nhật Nguyên - Báo cáo thực tập
 
Bài 1: Giới thiệu Android
Bài 1: Giới thiệu AndroidBài 1: Giới thiệu Android
Bài 1: Giới thiệu Android
 
Mixing asp.net mvc & web form into hybrid project
Mixing asp.net mvc & web form into hybrid projectMixing asp.net mvc & web form into hybrid project
Mixing asp.net mvc & web form into hybrid project
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Revit API & WPF Training - 15 Lessons | Alpha BIM 2023
Revit API & WPF Training - 15 Lessons | Alpha BIM 2023Revit API & WPF Training - 15 Lessons | Alpha BIM 2023
Revit API & WPF Training - 15 Lessons | Alpha BIM 2023
 
Pham Anh Tu - TK Framework
Pham Anh Tu - TK FrameworkPham Anh Tu - TK Framework
Pham Anh Tu - TK Framework
 
Báo cáo thực tập chuyên nghành lập trình Android GPSGroup
Báo cáo thực tập chuyên nghành lập trình Android GPSGroupBáo cáo thực tập chuyên nghành lập trình Android GPSGroup
Báo cáo thực tập chuyên nghành lập trình Android GPSGroup
 
1 gioithieuveandroidsdk-150322215607-conversion-gate01
1 gioithieuveandroidsdk-150322215607-conversion-gate011 gioithieuveandroidsdk-150322215607-conversion-gate01
1 gioithieuveandroidsdk-150322215607-conversion-gate01
 
Slide bài giảng lập trình Android DTU - Phần 1
Slide bài giảng lập trình Android DTU - Phần 1Slide bài giảng lập trình Android DTU - Phần 1
Slide bài giảng lập trình Android DTU - Phần 1
 
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
 
429157477-Slide-Bao-Cao.pdf
429157477-Slide-Bao-Cao.pdf429157477-Slide-Bao-Cao.pdf
429157477-Slide-Bao-Cao.pdf
 
Jdeveloper12c
Jdeveloper12cJdeveloper12c
Jdeveloper12c
 
Bài tập Lập trinh viên thiết bị di động
Bài tập Lập trinh viên thiết bị di độngBài tập Lập trinh viên thiết bị di động
Bài tập Lập trinh viên thiết bị di động
 
01 chuong01tongquanveasp netmvc5
01 chuong01tongquanveasp netmvc501 chuong01tongquanveasp netmvc5
01 chuong01tongquanveasp netmvc5
 
Asp.net mvc framework qua cac vi du
Asp.net mvc framework  qua cac vi duAsp.net mvc framework  qua cac vi du
Asp.net mvc framework qua cac vi du
 
mp_hag_slide_android_2321.pptx
mp_hag_slide_android_2321.pptxmp_hag_slide_android_2321.pptx
mp_hag_slide_android_2321.pptx
 
The First 2015 Saigon WordPress Meetup
The First 2015 Saigon WordPress MeetupThe First 2015 Saigon WordPress Meetup
The First 2015 Saigon WordPress Meetup
 
Tim hieugooglecode tortoisesvn
Tim hieugooglecode tortoisesvnTim hieugooglecode tortoisesvn
Tim hieugooglecode tortoisesvn
 

Android dynamic module

  • 1. Android Dynamic Module Lập trình module động trong Android Phí Ngọc Chi – CTO Eway JSC chipn@eway.vn | facebook.com/phingocchi
  • 2. Cập nhật Ứng Dụng Android APK APK Module v 2.0 Module v 1.0 … … … … ,,, … Server Client
  • 3. Cập nhật Module APK APK Module v 2.0 Module v 1.0 … … … Server Client
  • 4. Ưu điểm cập nhật theo Module Mềm dẻo và linh động  Khả năng mở rộng tốt  Đơn giản hóa việc cập nhật với người dùng  Dung lượng cập nhật nhỏ  Tốc độ cập nhật nhanh tức thời 
  • 5. Dynamic Module   Module được phát triển như một project độc lập và đóng gói thành file module.apk Ứng dụng chính tải file module.apk từ URL  DexClassLoader: thư viện sử dụng để nạp class động từ file module.apk  Java Reflection: khởi tạo object từ class động và tương tác với object để kích hoạt logic thực thi
  • 6. Module.apk – v2.0 Module … Download Module Load Module DexClassLoader APK Module.apk – v1.0 Java Reflection Quy trình cập nhật Module Load Module Class New Instance Invoke Method Active Module
  • 7. DemoModule Code public class DemoModule { public void show() { Toast.makeText(getApplicationContext(), "Hi! version 1.0", Toast.LENGTH_SHORT).show(); } } DemoModule.apk - v1.0 public class DemoModule{ public void show() { AlertDialog dialog = new AlertDialog.Builder(this).create(); dialog.setMessage("Hi! version 2.0"); dialog.show(); } } DemoModule.apk – v2.0
  • 8. Download DemoModule public void downloadDemoModule(Context context) { String dexPath = new File(context.getDir("dex", Context.MODE_PRIVATE), "DemoModule.apk").getAbsolutePath(); //TODO: download DemoModule.apk from URL to dexPath File }
  • 9. Load DemoModule public DexClassLoader getDemoModuleClassLoader(Context context) { String dexPath = new File(context.getDir("dex", Context.MODE_PRIVATE), "DemoModule.apk").getAbsolutePath(); String optimizedDirectory = context.getDir("temp", 0).toString(); String libraryPath = null; ClassLoader parent ClassLoader = context.getClassLoader(); DexClassLoader dexClassLoader = new DexClassLoader(dexPath, optimizedDirectory, libraryPath, parentClassLoader); return dexClassLoader; }
  • 10. Active DemoModule DexClassLoader classLoader = this.getDemoModuleClassLoader(this); try { Class<?> demoModuleClass = classLoader.loadClass("com.simple.DemoModule"); Object demoModule = demoModuleClass.newInstance(); demoModuleClass.getMethod("show").invoke(demoModule); } catch (Exception ex) { ex.printStackTrace(); }
  • 12. Thanks for your attention! Phí Ngọc Chi – CTO Eway JSC chipn@eway.vn | facebook.com/phingocchi