After updating Android Studio to 1.0, I see this error:
Error: Library projects cannot set applicationId. applicationId is set
to 'com.super.app' in default config.
I updated the Gradle plugin as suggested but I did not understand how to fix this.
Based on this info:
ApplicationId in Library Projects
You cannot use applicationId to customize the package of a library project. The package name has to be fixed in library projects (and specified as packageName in the manifest). The Gradle plugin did not enforce this restriction earlier.
Removing applicationId variable from the library's build.gradle file should resolve the issue.
Thanks to Joel for his correct answer: I need to remove only 1 line from te .gradle file:
defaultConfig {
applicationId "com.super.app" <---- remove this line
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
becomes
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
and my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.super.app">
...
This is the right solution if you don't need to rename the package name of your app. To rename it you need to use "flavours":
android {
...
productFlavors {
flavor1 {
applicationId 'com.super.superapp'
}
}
Libraries can't set applicationId and if you are working in a multi-module project and picking up flavors from a separate file , none of the above answers will work. For a modularized app, you need the following steps -
Create a flavors.gradle file in project root directory
ext.flavorConfig = { // 1
flavorDimensions "pricing"
productFlavors {
free {
dimension "pricing"
ext.myApplicationIdSuffix = '.free' // 2
}
paid {
dimension "pricing"
ext.myApplicationIdSuffix = '.paid'
}
}
productFlavors.all { flavor -> // 3
if (flavor.hasProperty('myApplicationIdSuffix') && isApplicationProject()) {
flavor.applicationIdSuffix = flavor.myApplicationIdSuffix
}
}
}
def isApplicationProject() { // 4
return project.android.class.simpleName.startsWith('BaseAppModuleExtension')
}
In 1 we export a closure so that we can use it in our modules’ build.gradle files.
In 2 we define a custom myApplicationIdSuffix property. We cannot simply have applicationIdSuffix as it is not possible to use it in library modules (build would fail if you did).
In 3 we iterate over created flavors and set applicationIdSuffix if we detect that it’s an application module only.
4 is a way to check where this closure is being used.
All that’s left is to use this closure in our modules’ build.gradle files. E.g. in application module this would look like this:
apply plugin: 'com.android.application'
apply from: "${rootProject.projectDir}/flavors.gradle"
android {
// other config...
with flavorConfig
}
If this isn't clear, you can check out this article for better understanding.
Just incase it helps some one :
When i imported an eclipse project into android studio,i got an error ::
"Error:Application and test application id cannot be the same"
Strange though,but i looked into the build.gradle and found the two placeholders,one for the application and other for testapplication.
I removed the testApplicationId from that as is suggested in this post and this helped me resolve the issue.
Note: This explaination is not related to the errors posted in this question,but might help someone who is getting a similar error.
You cannot define applicationId for your lib.
But incase you want to use an identifier in your build file, which will give you, your library package name, you can define a variable for the module and then use the value as required.
eg : Library's build.gradle
apply plugin: 'com.android.library'
def libraryGroupId = 'com.google.example'
def libraryArtifactId = project.getName()
def libraryVersion = '1.1'
Also, you can use the value below as needed in your build file itself in lib.
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "$libraryVersion"
resValue "string", "Library", libraryGroupId"
}
}
Related
I am trying to add some functionality to an existing application. The app's build.gradle contains several productFlavors and a couple of buildTypes. I have tried to replicate that as best I can in my dynamic-feature module, but I cannot seem to get it to install properly from Android Studio.
I followed the example from: https://github.com/googlearchive/android-dynamic-features to set up my feature module, so my project is structured like
app
features/module/build.gradle
build.gradle
I added a buildType and flavor to the app build.gradle
defaultConfig {
minSdkVersion 24
targetSdkVersion 28
}
dynamicFeatures = [":features:module"]
buildTypes{
myBuildType {
debuggable true
multiDexEnabled true
}
}
flavorDimensions "blah"
productFlavors{
arm64 {
ndk {
abiFilters "arm64-v8a"
}
ext {
abiVersionCode = 5
}
matchingFallbacks = ['defaultFlavor']
}
}
and in the module build.gradle, I have attempted to match that with:
defaultConfig {
minSdkVersion 24
targetSdkVersion 28
}
buildTypes {
dynamic {
multiDexEnabled true
debuggable true
}
}
flavorDimensions "blah"
productFlavors {
arm64 {
ext {
abiVersionCode = 5
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':app')
}
In my Run->Edit Configuration screen, I have put a checkbox next to both the base app and the module under the dynamic features to deploy section. I am trying to test this on a Nokia 6, with Android 9.0 running on it. The only output I get from the build is:
01/12 22:39:25: Launching 'app' on HMD Global TA-1025.
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_INVALID_APK
The APKs are invalid.
It just happened to me.
Turns out I was setting different flavors for different modules.
Try selecting the same variants under View > Tool Windows > Build Variants.
Please check those things
1) making sure that the AndroidManifest.xml package name was the same as the
build.grade applicationId
2) check package name in your Androidmanifest.xml see whether started with one empty
space character. like " com.example.test" instead of "com.example.test"
and make sure contain at least one dot in your package name
like "com.exampletest" instead of "comexampletest"
https://code.google.com/p/android/issues/detail?id=55841
3)"Build" > "Clean Project"
4)reboot the android system
Try Edit Configurations > Installations Options > Deploy APK from app bundle
I found a solution that resolved my problem. Make sure your libraries and class paths are up to date. I had a class for firebase plugins that were out of date. This problem occurred when using the new graddle. After updating the classpath, everything looks fine.
In my case. I changed this
classpath 'com.google.firebase:firebase-plugins:1.1.0'
to this
classpath 'com.google.firebase:perf-plugin:1.3.1'
I had same problem when I used Flavors (Build variants) in my app.
The solution for me was select another build variant in Build Variants tab (for example, release instead of debug flavor), then select the correct build variant, and then Clean, Rebuild.
I found this solution here: https://stackoverflow.com/a/65630971/6543967
I am trying to write an android app, which used to build once upon a time. Now, everytime I build, I get the following error:
Caused by: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
C:\Users\Jay\AndroidStudioProjects\DndTools-App\app\build\intermediates\merged_manifests\debug\AndroidManifest.xml:2: AAPT:
error: attribute 'package' in <manifest> tag is not a valid Android package name: 'dndtools'.
I originally started off with an android-kotlin tutorial as the base, since I wanted to familiarize myself with kotlin and android, if that might be relevant. Also, "Merged Manifest" has package = dndtools instead of com.dndtools.android.dndtools listed, also not sure if relevant.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.dndtools.android.dndtools">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name" //dndtools
...
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
def androidSupportVersion = '28.0.0'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "dndtools"
minSdkVersion 21
targetSdkVersion 28
...
I have searched the internet, and others who had this error usually had an underscore at the start or end of their applicationId (which is not the case here), so I am really at a loss
Change applicationId "dndtools" to applicationId "com.dndtools.android.dndtools".
applicationId in your build.gradle file is what is used as the real package, that's why you can see it in the merged manfiest as well. Update it to match the one you have in your Android Manfiest and it should work fine.
As for why it's an invalid package - it needs to have at least one dot in it to be installable on Android.
My problem was with uncorrect naming of the package id. I put something like com.example.3d. You can't start with the number like 3d.
In my Case, I have updated the Android studio to version 3.5.3, and while project setup, by mistake I have added applicationIdSuffix = kotlin_version, so this is what causing the problem.
So simply removing this line helped me to fix this issue.
in my case, i build app use default config
compileSdkVersion 30
defaultConfig {
applicationId "com.webview.app"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
applicationIdSuffix kotlin_version
}
when i add productFlavors
flavorDimensions "default"
productFlavors {
test01{
dimension "default"
applicationIdSuffix ".test"
versionNameSuffix "-test00"
}
test01{
dimension "default"
applicationIdSuffix ".test"
versionNameSuffix "-test01"
}
test01{
dimension "default"
applicationIdSuffix ".test"
versionNameSuffix "-test02"
}
}
then i'm runing my app, i got this message
tag is not a valid Android package name: 'com.webview.app.1.4.21.jb'
i think the problem shoud be number and point(.) can not be package name, so i delete code
applicationIdSuffix kotlin_version
it's work for me, because kotlin_version value it's ext.kotlin_version = "1.4.21", when my appid contain number and point(.) it cannot working. in android the appid(pacakege name) should be like this 'come.domain.project' it is reverse domain name.
A full Java-language-style package name for the Android app. The name may contain uppercase or lowercase letters ('A' through 'Z'), numbers, and underscores ('_'). However, individual package name parts may only start with letters
Is it possible to use some external reference or variable in build.gradle files?
I have several build.gradle files in my app source files, including the one for module app, module base, module player, etc. (it depends on the structure of your code and the names of your packages).
Inside of each of these files is the following or similar structure:
defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0.001"
}
Is there any way I can code this the way that I don't have to change these values in every file? Is it possible to use some external reference or variable and that way I can edit my versionCode, versionName, etc. just on one place?
In your Project gradle
ext {
minSdkVersion = 14
targetSdkVersion = 26
compileSdkVersion = 26
buildToolsVersion = '26.0.2'
// App dependencies
supportLibraryVersion = '26.1.0'
mockitoVersion = '1.10.19'
roomVersion = "1.0.0"
}
In your App gradle
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
.
.
}
}
dependencies {
// App's dependencies, including test
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
}
Go to File/Project structure/app/flavors then you can get versionCode, versionName, etc then change them what you want and it effects all of your Files.
Check this Image
Yes it is.
In your project-level Gradle config (the one in the root of your project, outside any module folders), you can define variables under the buildscript block:
ext.thisVersionCode = 1
ext.thisVersionName = "1.0.001"
Then you should be able to reference them from your module-level configs:
defaultConfig {
versionCode = rootProject.ext.thisVersionCode
versionName = rootProject.ext.thisVersionName
}
You can define variables in top level build.gradle file and then reference these variables in each module's build.gradle - that way youll be changing them only once in one file.
to give you an example,this is top level file https://github.com/Ejstn/android-starter/blob/master/build.gradle
and this one is module level file: https://github.com/Ejstn/android-starter/blob/master/app/build.gradle
You can also declare whole dependency as variable like in this google's app: https://github.com/google/santa-tracker-android/blob/master/build.gradle
I want to upload a new version of my app, but I can't because I added flavors so the package name has changed from:
com.myapp.android
to
com.myapp.android.flavor1
Inside my build.gradle:
productFlavors {
main {
applicationId 'com.myapp.android'
versionName '1.0'
versionCode 4
}
flavor1 {
applicationId 'com.myapp.android.flavor1 '
versionName '1.0'
versionCode 5
}
}
If I change the applicationId of flavor1 to 'com.myapp.android' I get this error:
Error:Execution failed for task ':app:processMainDebugGoogleServices'.
No matching client found for package name 'com.myapp.android'
So my question is, should I try to fix that error (and if yes how?) or is there any other work around ?
I haven't tried this, but reading the docs it seemd that just taking "applicationId" out of both flavor sections (main and flavor1) should work fine.
The new applicationId should be in your google-services.json as well.
Hi I have a common module for two apps,and I want to add a dependency in that common module if I am running on a certain app,I tried the code below,but that didn't work.
if (project.getName() == 'MyApp')
{
compile 'com.facebook.react:react-native:0.49.5'
}
Any help is appreciated.
This post Might be helpful for you. It sounds like creating different product flavors is an option for creating dependency conditions.
Update:
Adding examples of productFlavors from android studio documentation
android {
...
defaultConfig {
minSdkVersion 8
versionCode 10
}
productFlavors {
flavor1 {
applicationId "com.example.flavor1"
versionCode 20
}
flavor2 {
applicationId "com.example.flavor2"
minSdkVersion 14
}
}
}
dependencies {
flavor1Compile "..."
...
flavor2Compile “...”
}
If this isn’t sufficient for your needs you could always have your dependencies rely on external project dependencies, an example from the above post I mentioned is here:
dependencies {
compile "com.squareup.leakcanary:leakcanary-android"+(project.ext.has("leakCanary")?"":"-no-op")+":1.3.1"
}