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!
Related
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.
I want to deploy PhoneGap app on the Android simulator provided with eclipse. I decided to use Dojo Toolkit which heavily relies on the " _ " convention (starting a file/folder with " _ " means this is a private/internal module).
Basically the problem is that while deploying the app, every file/folder starting with "_" is omitted. This completely messes things up, Dojo toolkit as exptected fails to work.
Is there a way to fix this?
aaptOptions{
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
add the above lines in the application build.gradle file inside android block for android app
First go star this issue so Google will fix the bug eventually. If you are running on Mac or Linux there is a patched aapt that fixes the bug here. Other than that your only choice is to do a build of Dojo so that it is only in one file.
From the previous answer I ended making changes on ant.properties which is located at root of project with this:
aapt.ignore.assets=!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~
Here, I overwrote aapt.ignore.assets property defined on sdk-android directory. It works
For any Dojo developers out there, or anyone having issues with this in general.
What fixed it for me in Android Studio is opening the build.gradle, then adding to the android block:
android {
compileSdkVersion 26
...
aaptOptions {
ignoreAssetsPattern '!._'
}
}
A work around is to use dojo.js from the CDN
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.9.0/dojo/dojo.js"></script>
Also, I started looking for a minify app or service, which could create a single file from all the required dojo files, but did not find one easily.
Currently, I'm trying to integrate Crashlytics into an Android Application. However I can't get the app to be recognized and added to the Fabric Dashboard.
When using the Android Studio Fabric plugin following these steps:
New App
Select Crashlytics
Apply Code changes
Sync gradle
Rebuild project
Build app onto device (not virtual)
However when I do this, the Fabric plugin is still stuck on the "Please build and run your application" screen, and eventually gives an error message "It's been a while. Need some help?"
I've also attempted to install Crashlytics manually, by adding the code myself using this link: https://fabric.io/kits/android/crashlytics/install
But when I build the application, still nothing happens within my Fabric Dashboard.
I've attempted checking out the branch again and re-adding this code to no avail. I've also tried reinstalling the Fabric IDE plugin, restarting Android Studio and Restarting my machine.
I have successfully added Crashlytics to other applications following these same steps.
Any ideas?
I just had the same problem - nothing happened in the Fabric-plugin screen saying "Please build and run your application" during app-launches.
It started working after I disabled Instant Run (Preferences > Build Execution Deployment > Instant Run) then rebuilt and run the app.
Probably you forgot to add apply plugin: 'io.fabric' in start of your app level gradle.build file
I have had a similar problem - month ago I refactored package name and inserted wrong char to name (cyrillic с instead of latin c), what I only have seen now by viewing java code in hex-editor. In the build.gradle applicationId = "package name" was write similar as package name in *.java files, but only all chars were the right in latin.
Simple refactoring app package name to right name that equals the appliationId and clean/build project not solve that problem with the Fabric Crashlytics. May be wrong package name stay in another files, not only in *.java, manifest and gradle. I don`t know. Because I made fully refactoring by next step:
1) delete all lines of code that was added by Fabric plugin (if you used automatic code inserting) or that was added by you manually from build.gradle (app), AndroidManifest.xml, MainActivity.java.
2) replace old package name to new by Edit>Find>Replace in Path
3) manually copy all minimal needed project files to new project folder. I copyed these folder and files
NewProjectFolder/build.gradle
NewProjectFolder/app/build.gradle
NewProjectFolder/app/src/*
NewProjectFolder/app/libs/*
4) close current project, at "Welcome to Android Studio" select Import Project and select project in new project folder.
5) make some refactoring to run your app normally (I use Firebase, therefore I add this new app to my Firebase project in Firebase console and download the new google-services.json to NewProjectFolder/app/ )
6) be sure your app runs as well as before refactoring and stop it
7) start Fabric plugin, press "+New App" > "Crashlytycs" > "Install" > "Apply" to make auto-install fabric`s code to your build.gradle (app), AndroidManifest.xml, MainActivity.java.
8) run your app and wait "Done!" on Fabric plugin. After this you can see your app in Crashlytics dashboard.
It has worked for my project and I hope help to you.
I also had this problem. Make sure you rename your application package identically to what the application ID is.
For instance, I had the package structure com/exampleapp/, but it should have been com/companydomain/appname, because the application id was com.companydomain.appname
Have same issue here, i resolve doing these things:
First, add at your app build.graddle file:
defaultConfig {
applicationId "<your package name>"
}
If that doesnt resolve, try change your applicationId to other one, that doesnt match with your package.
For some reason, they worked here.
Also had this issue, then
I refactored my application package name
and
changed application id name in gradle
built it again and the issue was solved.
Make sure to include all dependencies on their dedicated gradle.build and meta in manifest file. Next is to throw a force runtime error on your device with internet connection also do not forget to initialize it first with Fabric.with(this,new Crashlytics()). If this doesn't work try to download Fabric for Android plugin in Android Studio and select your package.
This helped me:
https://developer.android.com/studio/build/optimize-your-build#disable-crashlytics-build-id
If you want to use Crashlytics with your debug builds, you can still
speed up incremental builds by preventing Crashlytics from updating
app resources with its own unique build ID during every build. Because
this build ID is stored in a resource file that is referenced by the
manifest, disabling automatic build ID generation also allows you to
use Apply Changes alongside Crashlytics for your debug builds.
To prevent Crashlytics from automatically updating its build ID, add the following to your build.gradle file:
android {
...
buildTypes {
debug {
ext.alwaysUpdateBuildId = false
}
}
I used to work with Android studio 1.4. yesterday I downloaded the newest version of android Studio 2.1.2 and it did not work well for me, so i reverted to Android studio 1.4.
the problem is, when i tried to run my App, I received a message telling me, "that the apk is already installed on the phone and to reinstall it i have to uninstall the version that is already on the phone".
Actually, I can not uninstall the apk version that is currently on the phone because it contains a huge database, and if i uninstalled it, then the databse content will be lost and i have to do it from the beginning
is there any other solution to run the App "apk" without uninstalling it
i am getting this message:
The easiest and the fastest way is to change application package name.
An appropriate way to do what you want would be to use ProductFlavours.
You start by adding the following to your app's build.gradle:
android {
productFlavors {
dev {
applicationId "com.yourapp.dev" //one in development mode
}
prod {
applicationId "com.yourapp" //the package name for your released app
}
}
}
You can add parameters different for the dev and production apk(s) as BuildConfig fields.
Do study more about it, will be able to implement it in the way you want. You can start with
Mastering product flavours on android
Just change the applicaitonId property in the app module's build.gradle.
Change version code and version name in build.gradle.
Hope this will help you.
1-First of All Please Change Your Current Application Package name
2-Build The Application
3-We can't use same package name in android
4-Work Will File after completion this steps.
Just change the applicaiton's Id property which is located in the app module's build.gradle.
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