2

I have some android project,most of them use the same code,only the picture and server api is different. So I fetch the common code to common library,named "common-library", and my project named "wch".

In the common-library has a "GlobalConstant.java",

enter image description here

each project is different. So my issue is how to override the GlobalConstant class in the "wch" project?

ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77
Aaron
  • 21
  • 2
  • Have you included "common-library" module in your "wch" project? – Dhaval Patel Nov 17 '15 at 13:48
  • I would place a method in a class like the application context class which returns an instance of the GlobalConstant class. Then you can extend this application context in your app project and return an other impl. of GlobalConstants. – Rene M. Nov 17 '15 at 13:50
  • yes,I included the "common-library" module in "wch" project. – Aaron Nov 17 '15 at 14:00
  • I tried create a GlobalConstant class in the "wch" project,I think when Android Sutdio complie the project will replace the common-library GlobalConstant class use "wch" GlobalConstant.It's a pity,it's output error: "com.android.dex.DexException: Multiple dex files define Lcom/bdb/lot/common/library/global/GlobalConstants" – Aaron Nov 17 '15 at 14:04

1 Answers1

0

You could use Build Flavors.

Configure the folder structure correctly (see this for reference) then you can just use a separate GlobalConstants class for each flavor.

Community
  • 1
  • 1
Kuffs
  • 35,581
  • 10
  • 79
  • 92