Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build multiple apps from one project with different app name, icon, settings,

Building iOS and Android apps with only one project is pretty awesome. But is it also possible to build multiple apps with different names, icons, etc.

This could be very helpful if you build apps with the same layout and maybe 95% same of the functions/code/algorithms:

  • different target-groups (recipes app for fitness, vegans, veggies, eco,...)
  • different sports (news for football, basketball, tennis ...)
  • different customers (business app for customer A, B and C)
  • ...

Things, which could be different per app:

  • App name
  • App icons
  • SplashScreen
  • Design
  • Settings (API URL, ...)
  • Some code (default function/components maybe could get overwritten by app-based custom files)

Maybe it would be the perfect solution if you have a directory flavors where you can put all the files which you want to use to overwrite the default code-base.

Somebody here who released something similar or any ideas how to solve this?

like image 343
rakete Avatar asked Nov 13 '17 13:11

rakete


3 Answers

This is a problem I have been solving in my projects last days. And I think I have some good (not perfect) solution so far.

Idea. We don`t have any built-in functions to help us handle this case, so we can use some external manipulation that can do the job. What we need is just multiple Android and iOS projects and single JS code base.

Implementation. I`ve come to this project structure:

  • ios
  • android
  • manager
  • src

ios and android folders is well known to you, they are native project folders.

src is a folder with JS code, you can organize it whatever you want

manager is most interesting one. Here we can store multiple native project files. We can have multiple native project folders in it, for example app1-android app1-ios app2-android app2-ios. And when we want to work on app1 we just copy app1-ios and app1-android to our root ios and android folders, so the actual project is app1. When we are done with app1 we can save android and ios folders to our manager and then just copy app2-ios and app2-android to root ios and android. And we are all good to develop our app2.

We can do it manually. But we are developers and we can make it much easier. I`ve written a PHP script that makes it as easy as php save.php -a app1 and php set.php -a app1 to copy from manager to root and backwards. Moreover, it takes care of not copying some unimportant staff (pods folder in ios, build in android etc.) and running pod install to ensure we have all pod in actual project.

I stick to one package.json file to have all npm modules installed once, so I don`t have to run npm install after each project switch.

Afterall, we can have as much projects as we wish in one repo, we can customize each one independently.

PS If you want me to share my scripts I`ll do it as fast as I can (need some time to prepare it for github and to write some more detailed instructions), just let me know.

like image 160
Roman Osypov Avatar answered Nov 15 '22 16:11

Roman Osypov


I did this for about 100 different native apps per platform (iOS/Android), sharing the same code base. I manage this setup for about 2 years now and I am still happy with it.

Here is the iOS part:

I use targets with different plist/pch files.

enter image description here

Save files that shuld differ per app in a separate directories, named by the app name. Check the corresponding target, if adding the file to the project:

enter image description here

By using the same filename you can "override" the file for different targets.

The Android part:

I use one gradle module for the common part and one module per app for the customizing. I also use gradle variables for common values definitions (minSdkVersion, compileSdkVersion etc.). Only the following settings differs per app: applicationId, versionCode, versionName. Here is an example file for a custom app:

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "..."
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 28
        versionName "1.0"
    }
    signingConfigs rootProject.ext.signingConfigs

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

}

dependencies {
    compile project(':apps:common')
}

You can override the resources (app icon, images, strings etc.) in the corresponding res folder of an app module (use the same filename for the same resource).

Don't forget to include all your modules in the settings.gradle.

like image 3
artkoenig Avatar answered Nov 15 '22 16:11

artkoenig


You can use multiple targets.

You can create target by below steps :

Go to project navigator -> Right Click on your app name under target -> Select Duplicate -> from popup select Duplicate only .

And you will find duplicate target. Now you can take another or extra app icon and launch image in your assets and for that target you can set it.

Refer below screenshots for better understanding!

enter image description here

enter image description here

enter image description here

So, select newly maded target and make changes by selecting it from general tab.

You can refer this great tutorial by Appcoda!

like image 1
Ketan Parmar Avatar answered Nov 15 '22 16:11

Ketan Parmar