1

I have an app and that's already been made for large devices i.e 10 inch tablets and kiosk. I made the same design for the mobile phones but that was not looking good ,so I thought to move the mobile device to material design and the rest of the devices (tablets & kiosk) would remain same.

I know how can I make different layouts for the different devices i.e normal , large and x-large but I am worried about the code. So basically followings are my confusions....

  • What is a best way to Judge which device my app is running on in code so that I have to run some methods on the basis of that because my normal device is following material design and contains some widgets that are not present in the design of tablets and kiosk i.e RecyclerView (for some purpose)?
  • I have searched a lot for this problem and came to a point that there are 2 ways of supporting multiple devices 1> make two separate apks , 2> Make one apk and check in code to differentiate the devices, but as i said above in point no#1 that i have material design in normal devices and that is completely changed design in terms of widgets and layouts , fragments and even navigation, so what would you suggest is the best way to handle this?
  • If I make 1 apk and put a check in code , then I must say I have a ton of code , and resources and in either case (if the device is normal and large) some resources and classes will never gonna used and will make apk size larger so what is a best way to make a work around about this problem ?

I have also searched through stackOverflow and only came up with these two links that were close to my question but rest of the links are about different layouts not the code:

  1. Android app for phone and tablet: 1 or 2 apps?
  2. Creating different layout for android phone and tablet

I hope I am quiet clear in my question please answer my these question with some authentic reasons and links.

Community
  • 1
  • 1
Umair
  • 6,366
  • 15
  • 42
  • 50
  • I think you must go for same apk , dont know if it is efficient in your app demands. – A.s.ALI Nov 08 '16 at 09:01
  • @AbdulSalamAli well it can be done but like I said what will happen to the code that is not being used but still being called .. ? – Umair Nov 08 '16 at 09:02
  • Are you using the Support Library? – Code-Apprentice Nov 18 '16 at 22:22
  • @Code-Apprentice yes I am using support libraries for android. – Umair Nov 20 '16 at 08:22
  • Then you can use the support version if RecyclerView for all versions of Android. – Code-Apprentice Nov 20 '16 at 08:24
  • Yes you are right but like I said working of both codes is different. even if I use the the same widgets still i will not solve my problem. Take for example on tablet I am doing 5 screens work on a single screen and on mobile it's not like that and when I will design for mobile I will have to use that single screen code on 5 different classes/activites. I just not want to use that code again and again. – Umair Nov 20 '16 at 08:29
  • Any good reason for the downvote I like to know ? – Umair May 29 '18 at 04:58

2 Answers2

3

Multiple apks for a single app is supported in Google Play. However, unless your app is very large (greater than 100MB) they recommend you release one apk for all devices.

So you need to inspect the screen size at run-time. You can do this by category, by device independent pixels, or even in inches. Then, as you said, you would load the appropriate layouts and fragments accordingly.

Even if you were to use different apks, you would likely do it in a similar fashion because you probably want to share SOME code.

In Gradle you would make productFlavors for each apk, along with a variable to define the build like this:

productFlavors {
    bigtablet {
        buildConfigField "String", "deviceType", "\"bigtable\""
    }
    smalltablet {
        buildConfigField "String", "deviceType", "\"smalltable\""
    }
}

Then at runtime you would use the BuildConfig.deviceType to drive the exact same logic as the screen size did in the one apk method. With this method Gradle will strip out all the unused code from each apk.

The last option would be create completely different projects for each apk. Pushing all the shared code into libraries.

You can always put it all in one apk for now and switch to multiple productFlavors if the apk grows too large. Since the logic is similar it wouldn't be too hard to swicth. Hope this helps.

Community
  • 1
  • 1
Mike
  • 5,482
  • 2
  • 21
  • 25
1

The Support Libraries are designed to minimize the amount of work you need to do to detect differences in the Android version where your app runs. For example, RecyclerView is available in the Support Library. Between this and layout-xxx folders, you can usually build a single APK for all API levels and device form factors.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268