I started to learn android using Android Studio 0.8.2 and I started a new project with the minimum API as 15. But in my AndroidManifest.xml, doesn't appear the uses-sdk tag.
Do I have to insert it by myself? Shouldn't the project create it? Or is Android Studio different and is no longer necessary to insert this in manifest, only in the build.gradle?
Thank you in advance :)
The default template in Android Studio is ready to work with gradle.
If you check your project you will find a build.gradle file inside your app module.
Here you can find something like this:
defaultConfig {
applicationId 'xxxx'
minSdkVersion 15 //your minSdk
targetSdkVersion XX //your targetVersion
versionCode 0
versionName '0.1.0'
}
Gradle building the project will override the uses-sdk tag in your Manifest.
Yes, add it manually.
Android studio uses build.gradle to build the project so it doesn't care about the manifest, and that's probably why it doesn't insert it in it. However, it is important to have it in the manifest, for when you publish the app, as Google play uses this for filtering the devices.
Related
I have developed an Android project with Android Studio and I want to install it on a device. The problem is that I want to install 2 versions of it. The only difference between them will only be the name.
I hope that you could help me.
As well as the name you will also have to change the applicationId.
The applicationId is what Android uses to detect if an app is unique.
If you are using gradle it will be within your modules build.gradle file like this
...
android {
...
defaultConfig {
applicationId "com.mycompany.appname"
...
}
You may also have to change provider authorities in your AndroidManifest.xml if you use them.
I recently try to open up a project developed sometime ago into Android Studio and try to rebuild it and I get whole load Android Pre Dex errors which I am totally stuck how I get rid of them. Tried a lot of stuff such as changing Android API level, cleaning, change jdk version.. all doesn't work.
Any experts out there can enlighten me what is the likely cause of these errors.?
android pre dex errors screenshot
Step 1: Add multidex enabled in default config
defaultConfig {
applicationId "Your package name"
minSdkVersion 16
targetSdkVersion 23
versionCode 5
versionName '1.0.5'
multiDexEnabled true
}
Step 2 : Add this library in your dependencies
compile 'com.android.support:multidex:1.0.0'
Step 3 : Add this line in your MyApplication extends Application java class
MultiDex.install(this);
Step 4: Don't forgot to call MyApplication class in your Application tag of manifest file. Like this
android:name=".MyApplication"
After this 4 steps clean your project and run the application. Surely it will helps you!
Happy Coding!
i already solved it
it happen because you didnt setting the default java in android studio 2.3.3 or android studio 3.0 beta 6
go to file > project structure > SDK location
change the JDK Location to C:\Program Files\Java\jdk1.8.0_131
Based on this Google document I'm expecting Gradle to update my manifest.xml file with a version number, notably this quoted section:
The defaultConfig element configures core settings and entries in the manifest file (AndroidManifest.xml) dynamically from the build system. The values in defaultConfig override those in the manifest file.
However when I change the version code or version name of my Gradle file, the values arent' changed in my manifest.
Is this normal behavior?
Which values, between the manifest and the gradle build, are stting version codes and names?
How can I make the connection between the manifest versions and the gradle build more visible?
Even I am facing the similar issue. It is the default behaviour of gradle system I guess. You need to update both AndroidManifest.xml and build.gradle seperately if there is any changes in sdk versions, version code, version name,etc. I am looking forward that these kinda issues must be fixed in upcoming releases.
I have versionCode(1.0.3) and versionName(8) in my build.gradle only and it had worked correctly for me in past.
Now I updated the versionCode to 1.0.4 and versionName to 1 but it kept on giving me error on Google play. I even tried adding the new versionCode and versionName to AndroidManifest.xml but it did not help. Only thing that worked was updating the versionName to a higher number (9). Something seems broken in the Google Play upload apk and verify mechanism. Hopefully my answer would save someone else's 1 hour for solving this silly bug.
I have an Android project targetting the Android SDK v21. Now I need to debug it on a device with Android 4.4 (i.e. SDK v20). How do I tell Android Studio to attach an older version of the source to the internal classes so that I can step through them?
Here the best solution is to set compile SDK version to 20. So that build tools will compile your project using SDK version 20 and you can debug your app.
When you use several modules in your project you need to set same compile SDK version to each module.
I can not confirm my answer works, but it is working for me.
I replace my compileSdkVersion, buildToolsVersion, minSdkVersion and targetSdkVersion with new one like following in my build.gradle file.
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.mytest"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
After changing it, you may not need to convert old to new or new to old sdk component.
You need to open module settings (Right click on your app module and select Open Module Settings or just select module and press ⌘ + ↓ on Mac)
And select compileSdk and buildTools to v20
Another way to do it is to open build.gradle file for the "app" module to change compileSdk and buildTools.
I would like to explain little before the solution.
Google provides the SDK APIs in the form of JAR (android.jar) files. The JAR files are stored at SDK LOCATION\platforms\android-API#.
For example the android.jar file for the Android 4.4(Kitkat) API-19 is located at YOUR SDK LOCATION\platforms\android-19\android.jar.
The Gradle compilation with the Android Studio uses the compileSdkVersion field in the build.gradle to select a specific android.jar for the compilation.
What is compileSdkVersion?
The version of the API the app is compiled against.
This means you can compile and use Android API features included in that version of the API
All the previous version features are also included during compilation.
If you try and use API 21 feature, such as public void openCamera (String cameraId, CameraDevice.StateCallback callback, Handler handler)
Added in API level 21 but set compileSdkVersion to 20, you will get a compilation error.
If you set compileSdkVersion to 21 you can still run the app on a API 20 device as long as your app's execution paths do not attempt to invoke any APIs specific to API 21.
How to set compileSdkVersion?
There are two ways
1. Selecting API from the GUI
1) Select "File->Project Structure..."
2) Select "app->Properties"
3) Set the "Compile Sdk Verion" from the drop down box to the required SDK version.
4) "compileSdkVersion" will be set automatically in the "app" module's
"build.gradle" file.
2. Setting the API in the gradle.build file
1) Open the build.gradle file of the "app" module
2) Set the compileSdkVersion to required value such as 19 for the API#19.
I hope that helps...
Happy Coding...
The best solution for me was to add a new module (Android Library) to the project and set the compile SDK to the requested api level. That way you can still compile your main app with the original SDK level but still get the sources integrated with your debugging Android version.
You can create a new Android Virtual Device with the preferred API level and debug the application on it.
Simply open module settings and change compileSdk and buildTools to v20
I'm using the latest and greatest IntelliJ Community edition. My application runs fine on the android emulator. However, I need the emulator to better match the Kindle Fire. I made the configuration changes in the AVD Manager (including setting device to API 10.)
When I went to my project to configure the project to target the new virtual device, I got the following message: "Build target of AVD DEV3 is not compatible with your build target."
It didn't take much work to figure out that the issue is related to my choice of API 10.
I don't know where I tell my project to use API 10. I looked all over and didn't see any references to the API level at all. Any ideas?
EDIT
I added
<uses-sdk android:minSdkVersion="10" />
to my AndroidManifest.xml file and was able to select the new device. I'm starting it up now.
The answer above is no longer true in Intellij (using gradle)
Now <uses-sdk> is ignored in the AndroidManifest.xml, it is automatically added to the built manifest file. To change the version, go to the 'build.gradle' file and look at the minSdkVersion.
As Tony and Blundell mention, the answer is to declare your minSdkVersion in your AndroidManifest.xml file. In this way, the application will be allowed to launch on any AVDs that at least meet the minSdkVersion.
Here's more documentation on the <uses-sdk> tag:
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
Set this value in the Gradle file - as shown here:
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.kotlinconverterapp"
**minSdkVersion 26**
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}