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.
Related
It has been a while since I have touched this project. I remember when I created it with the project creation wizard, I was asked for a minimum SDK level (or perhaps a target SDK level). Where do I go in the IDE to view and change this level?
I sort of expected the generated code to contain this information in the AndroidManifest.xml file, where it could be easily changed, however it does not seem to be there.
In general, it is defined in the build.gradle file of the main module(it is named as 'app' if you had not changed) of your project:
{YourProjectName}/app/build.gradle
the value which minSdkVersion stated inside defaultConfig block of android is exactly what you want!
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!
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
I want to import Android project in Android Studio and this is where the problem begins:
1) If I set Gradle home and click OK, I get the info:
2) And secondly, if I try to run project I get the message:
Trying both ways result in displaying messages above.
I have GRADLE_HOME, JAVA_HOME set correctly and ANDROID_HOME points to "sdk" directory in android-studio directory.
Much appreciation for answer with the solution.
Point to the folder <gradle root folder>/libexec. Things should start working.
Ok, I missed to download some build tools for specified android version, arrgh.. Anyway, thank you for your interest and the answers. I am quite new to gradle and Android studio. I have been developing android apps with intellij so far.
That worked for me:
1. Open Android SDK Manager.
2. Make sure that "Build tools ..." libraries are downloaded and it should work properly.
I'm going to respond to this cause I had a ton of problems.
what I did was in linux
in terminal
type "which gradle"
if there is a symlink follow this until you see where your gradle is located.
mine was located in the following.
/usr/lib/gradle/4.2/bin/gradle
so now just use
/usr/lib/gradle/4.2/lib is what you want to put in intelliJ
Try to use default gradle wrapper. Android studio will do everything correctly.
I had the same problem (Cause: unexpected end of block data) while importing a project, and resolved by setting ANDROID_HOME. export ANDROID_HOME=/android_sdk_root_dir
I had a "Cause: unexpected end of block data" as well. What I did was installing the right SDK version for Android. Check your build.gradle file.
In my case I needed API level 18:
android {
compileSdkVersion 18
buildToolsVersion "18.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
versionCode 1
}
...
}
I was facing the same issue, I went to http://gradle.org/gradle-download/ and downloaded the latest gradle. I then linked my project to the path where i had saved the gradle, and everything worked
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).