How to build 2 apps with the same project in android studio? - android

I've recently just imported my eclipse project into Android Studio, I haven't convert it into gradle yet. So some forum that offers me solution from gradle is not working. My problem is I have 2 application, where both has some slight difference. I want to use the same project when I deploy the application. I've tried to change the project name but that doesn't help. The moment the new application is installed, the previous version is overwritten. I thought of making some changes to the Manifest file(not sure if this is the right thing to do) but in android studio, I can't seem to locate where the file is. Please help.
Regards,
Dexter

Your application needs to have a different package name for it to be treated as a different app.
So instead of
com.yourcompany.apps.yourapp
You write
com.yourcompany.apps.yourapp1 and
com.yourcompany.apps.yourapp2
You can do that in your AndroidManifest.XML in the manifest tag
package="com.yourcompany.apps.yourapp1"
Also, instead of 2 separate apps, try seeing if you can solve this using Build variants and product flavors.

Use flavors on your build.gradle
productFlavors {
flavorName {
minSdkVersion 19
applicationId 'you.package.name'
targetSdkVersion 23
versionCode 1
versionName 'version_name'
}
}
Also you can modify a file with different changes by just adding a source folder for the flavor.
app
|--src
|--main
|--flavorName

Related

Create Android Studio SDK Project like Xcode Framework

I'm sorry if this has been asked, but I can't seem to find it. Coming from iOS, in Xcode, you can create a new Framework (SDK) project. In Android Studio, I cannot for the life of me figure out how to do that. I can create a Project, and then create a new module, Android Library. Is that the only way to do it? To do it with an accompanying "app"? I couldn't seem to find any other way.
Also a side question, is there a reason why if you name a project my-project, it creates packages as com.mycompany.my_project. Is there any way getting around that besides naming your project as MyProject?
The "Android Library Module" is actually equivalent to Xcode framework concept.
Is that the only way to do it? To do it with an accompanying "app"? I couldn't seem to find any other way.
At the moment, yes, creating a project then creating a new library module and deleting the app module is the easiest way.
This link Android Studio Rename Package tells how to rename the package name.
For how to change application ID, see here: https://developer.android.com/studio/build/application-id
android {
defaultConfig {
applicationId "com.example.mylibary"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
...
}
Also note that, Android Library project does not have applicationId.

How to get versionCode into react native code (android)

Question
Is it possible to either add things to the default props of the index.android.js from the build.gradle or any file at runtime?
OR
Grab the versionCode from the build.gradle file from within my react-native code?
Problem
I'm trying to programmatically have a version number in my application based on the version, build and git sha. The format is essentially version-gitsha-jenkinsBuildNumber (for example 1.0.0-abc1234-83). I was able to get this to work on iOS by using a bash script to add it to the Info.plist and then followed How to read Info.Plist at run-time in react-native iOS app? in order to add them to my default props in my index.ios.js. I cannot find a way to do this in the build.gradle.
What I've Tried
Right now, I'm replacing the versionName string in the defaultConfig with the git sha using something similar to what I found here: How to update version number of react native app
Then grabbing it inside react native with react-native-device-info. I'm also pulling the version number 1.0.0 from the package.json. Lastly I wanted to add the jenkins build number to the versionCode of the defaultConfig but I have no way of getting it out with react-native-device-info.
Any help would be much appreciated!
I ended up running a script at build time that will cat the version number and etc into a version.json file. Then on runtime, the .js file will import that json file and read it from there. It was the least complicated and cleanest way I thought of and it works well!

How to change package name in android studio? [duplicate]

This question already has answers here:
Rename package in Android Studio
(55 answers)
Closed 7 years ago.
I have made an app and it is my very first app so when I started coding, I left the package name as com.example.stuff and now when I try to upload to the play store it wont let me due to the package name. I have tried refactor-> rename the package name and changed it in the AndroidManifst.xml then I tried to upload again. I am once again left with the same message time after time.
I appreciate any help and thanks in advance. :)
First click once on your package and then click setting icon on Android Studio.
Close/Unselect Compact Empty Middle Packages
Then, right click your package and rename it.
Thats all.
In projects that use the Gradle build system, what you want to change is the applicationId in the build.gradle file. The build system uses this value to override anything specified by hand in the manifest file when it does the manifest merge and build.
For example, your module's build.gradle file looks something like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
// CHANGE THE APPLICATION ID BELOW
applicationId "com.example.fred.myapplication"
minSdkVersion 10
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
}
applicationId is the name the build system uses for the property that eventually gets written to the package attribute of the manifest tag in the manifest file. It was renamed to prevent confusion with the Java package name (which you have also tried to modify), which has nothing to do with it.
It can be done very easily in one step.
You don't have to touch AndroidManifest.
Instead do the following:
right click on the root folder of your project.
Click "Open Module Setting".
Go to the Flavours tab.
Change the applicationID to whatever package name you want. Press OK.

Crashlytics - different package names for different gradle flavours

I am trying to setup an Android app, using Android Studio with 2 different flavours. Each flavour changes packageName and applicationId - since I want 2 separate APK's submitted as 2 different products to Google Play.
I also try to setup separate apps in Crashlytics, one for each flavour. Although the first one was created without any problem, when I switch flavour, Crashlytics plugin for Android Studio still thinks that my project is already setup. So currently I cannot setup my Crashlytics for second flavour properly.
Thanks in advance for any suggestions.
As suggested by m4ch3t3 this workaround worked perfectly:
I created an empty project with package name matching the other
flavour. Using this project I created new app in Crashlytics. Then I
compiled both flavours of my real project and caused fake crashes in
them. Crashes were reported into matching Crashlytics apps
You can define different package name by definining applicationId in your app build.gradle as follow:
productFlavors {
dev {
applicationId "dev.myapp.app"
}
prod {
applicationId "prod.myapp.app"
}
}
Using the Crashlytics plugin for Android Studio will be a PITA in your case.
What you really need is only the API key and secret - shared among the same organisation - so if you already have one app correctly deployed on Crashlytics you can access those data from your organisation profile.
Just log out from the android studio plugin (CTRL+L while the plugin popup is focused), and take a look at this answer that explain how to deal with multiple flavour and multiple keys.

RenderScript Android Sample example RenderScript >HelloCompute is not compiling

I'd like to do some experiment with renderscript, so I started with the example shipped with the sdk, but unfortunatly I am not able to compile it.
Is there any extra tool which I might required to compile and build that example, I'd tried to read the doc. but they haven't mentioned anything.
The problem with the Sample project is...
I came to know after building the project eclipse will generate new files in res/raw folder and some files in gen folder, and this files can be used in java files, but this files are not generating. can anyone guide me how to solve this errors.
Thanks,
After about three days of struggling with this, I found that the problem was with the project folder structure, when compiling with gradle. This project shows the correct structure:
https://android.googlesource.com/platform/tools/build/+/11086782041b302109e8349e13b8f9d5e305341d/tests/renderscript/
In short, the .rs files should not be together with the java files, but in a separate folder called 'rs' alongside java and res, with the same inside structure, such as "...\HelloRSProject\HelloRS\src\main\rs\com\example\hellors\mono.rs". Also, be sure to add renderscriptTargetApi to the build.gradle file, like so:
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 16
renderscriptTargetApi = 16
}
}
There is a bug in ADT 22. I've already reported it here(you can find temporary workaround there, too).

Categories

Resources