Android Studio 2.2 update cause DefaultManifestParser cannot be resolve - android-gradle-plugin

Recently I updated android studio to android studio 2.2 and using gradle 2.14.1. However, com.android.builder.core.DefaultManifestParser cannot be resolve after the update. Below are the codes that I am using. Any recommend workaround to solve this issue? Thanks
defaultConfig {
def manifestParser = new DefaultManifestParser(android.sourceSets.main.manifest.srcFile)
applicationId = manifestParser.getPackage()
versionName = manifestParser.getVersionName()
versionCode manifestParser.getVersionCode()
minSdkVersion manifestParser.getMinSdkVersion()
targetSdkVersion manifestParser.getTargetSdkVersion()
multiDexEnabled true
}

My defaultConfig setting is similar to yours and it's successfully built,
defaultConfig {
def manifestFile = (File) android.sourceSets.main.manifest.srcFile
def manifestParser = new DefaultManifestParser(manifestFile)
//noinspection GroovyAssignabilityCheck
applicationId = manifestParser.getPackage()
minSdkVersion 18
targetSdkVersion 23
//noinspection GroovyAssignabilityCheck
versionName = manifestParser.getVersionName()
//noinspection GroovyAssignabilityCheck
versionCode = manifestParser.getVersionCode()
}
so I guess probably the required *.jar hasn't been successfully downloaded during the IDE update. Could you double check whether the file builder-2.2.0.jar exists under the IDE folder(e.g., C:\Program Files\Android\android-studio_2.2\gradle\m2repository\com\android\tools\build\builder\2.2.0). If it does exist, can do a further checking to make sure the file DefaultManifestParser.class is really inside folder \com\android\builder\core by extracting builder-2.2.0.jar.
If the above mentioned file and class do exist, can also try using import com.android.builder.core.DefaultManifestParser, however, it's a bit weird that we have to use this.
Just think of there is another thing to check is the Gradle plugin class path, it should be like this
classpath 'com.android.tools.build:gradle:2.2.0'

I have same troubleļ¼Œand reback gradle version to 2.1.3 it is working
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}

Related

Execution failed for task ':realm:stripDebugDebugSymbols'

After installing realm in react native and setting up all necessary things console give me this error after starting project (npm run android);
Execution failed for task ':realm:stripDebugDebugSymbols'. NDK at C:\Users\123\AppData\Local\Android\Sdk\ndk\21.4.7075529 did not have a source.properties file.
I check ndk in android studio (after opening project in it) in Android SDK --> SDK tools sections, the ndk already installed. I also change the ndk version (one by one) in android/build.gradle according to some other stackoverflow solutions but didn't work. Below is android/build.gradle code;
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"//"25.1.8937393"//"21.1.6528147"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
This is a android studio screen shot of sdk tools SDK tools

How to display current version number from build.gradle in app?

What is the best approach to display the current app version number in the app? Specifically, android\app\build.gradle has a "defaultConfig" object with "versionCode" and "versionName" properties. So let's say the current build.gradle configuration looks like this:
defaultConfig {
versionCode 9
versionName "0.1.9"
}
What would the code/implementation look like in order to pull this info from build.gradle and display it in a Text component in a parent component? I know that I could simply copy this information from the build.gradle configuration and paste it directly into the Text component. But the point of what I'm trying to do is to be 100% sure of the currently installed version of the app by propagating up that info into an app view directly from build.gradle.
Try installing the React Native Device Info Link component to get the build details as specified in the Gradle config.
Once installed you can use:
DeviceInfo.getVersion()
To output the version, and:
DeviceInfo.getBuildNumber()
To get the build number.
I use the package.json version as the app version. So we get the app version from package.json. when we change the package.json, the app version also changes.
const PackageInfo = require("../../../package.json");
localVersion : PackageInfo.version
but we have to first modify the native Android, to make it use the package.version as version name and code.
//in android project.build.gradle
def getNpmVersion() {
def inputFile = new File("../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}
def getNpmVersionArray() {
// major [0], minor [1], patch [2]
def (major, minor, patch) = getNpmVersion().tokenize('.')
return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[]
}
subprojects {
ext {
def npmVersion = getNpmVersionArray()
versionMajor = npmVersion[0]
versionMinor = npmVersion[1]
versionPatch = npmVersion[2]
}
}
// then in app.gradle use it
defalultConfig{
...
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
...
}
Firstly, this might be a duplicated question. You can check this How to get a versionName in react-native app on Android?.
Secondly, if you're using CodePush to update your code, the above solution won't work because it only gets version of native built app.
If that's not what you need, please provide more details about your problem.
Also make sure to specify them in your build.gradle file instead of the AndroidManifest.xml:
defaultConfig {
versionCode 1
versionName "1.0"
}

How to specify the minSdkVersion in react native project

I have created react native project using create-react-native-app
I can see that there is a sdkVersion property in app.json, but I want to specify minSdkVersion for the app.
How do I specify the minSdkVersion in react native project?
You can change it from app/build.gradle directly
Open the project go to the android/app folder and open build.gradle file.
In this you can find
defaultConfig {
applicationId "PACKAGE_ID"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
change this minSdkVersion 16 according to your requirement
I have these settings in the android\build.gradle file as per below...
buildscript {
ext {
supportLibVersion = "28.0.0"
buildToolsVersion = "28.0.3"
minSdkVersion = 23
compileSdkVersion = 28
targetSdkVersion = 28
}
}
You might like to notice that react-native lib/package/module (as you wish) sets the minSdkVersion to 16. You can see it here on their official build.gradle file:
android {
compileSdkVersion 28
...
defaultConfig {
minSdkVersion(16)
targetSdkVersion(28)
versionCode(1)
versionName("1.0")
}
...
}
https://github.com/facebook/react-native/blob/7a72c35a20a18c19bf6ab883cb2c53a85bd4c5c0/ReactAndroid/build.gradle#L356
By setting minSdkVersion to 16, react-native uses Android API's natively supported by at least KitKat version.
You may see the official Platform Version Dashboard here:
https://developer.android.com/about/dashboards/index.html

React Native : Change targeted sdk version for play store upload

In Play Store I am trying to upload my app but I'm getting a warning i.e. mentioned below:
Target API level requirements from August 2018
Warning:
Your app currently targets API level 22 and must target at least API level 26 to ensure it is built on the latest APIs optimized for security and performance.
From August 2018, new apps must target at least Android 8.0 (API level 26).
From November 2018, app updates must target Android 8.0 (API level 26).
Open build.gradle under android/app/
find the android { } block
Change the following version to the below:
compileSdkVersion 27
buildToolsVersion "27.0.3"
minSdkVersion 16
targetSdkVersion 27
In the dependencies block, change the appcompat line to match the target version
compile "com.android.support:appcompat-v7:27.1.1"
In case your current android/app/build.gradle has lines which look like
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
You will have to edit the android/build.gradle to include
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 21
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
...
}
Although I do not know where to get the latest versions.
It would be great if someone could edit this to include where to get the latest version numbers
From August 2021, API level should be 30 or above.
I have React Native app and my android/app/build.gradle looks like below
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
Changed the android/build.gradle to have below content which worked
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "20.1.5948944"
}
....
Just change targetVwersion to 26 in ./android/app/build.gradle
for the maven part, mentioned by #Bodhish, I needed to do it this way:
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
url 'https://maven.google.com'
}
maven {
// All of React Native (JS, Obj-C sources, Android binaries)
// is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
with this piece added in addition to #albert's comment resolved for me.

Gradle upgrade 4.1 doesn't load versionCode and versionName

I upgraded my gradle to 4.1
project.ext.set("currentGradleVersion", "4.1")
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
I moved all the "compile" to "implementation" since "compile" is deprecated.
Also changed variant.outputs.each to variants.outputs.all
The apk generates with the correct versionName
But when I used aapt command "./aapt d badging **.apk"
All the below are returned as empty, what went wrong?
versionCode='' versionName='' platformBuildVersionName=''
After some ... long.. researches :
Here are some solutions to update the versionCode and versionName:
Gradle 3.0.0 alpha variant output issue
Gradle plugin 3.0 rewrite versionName
In a Brief :
It is something no more supported by the latest gradle version.
To fix it, you can ADD this piece of code in your current code :
applicationVariants.all { variant ->
...
variant.outputs.all { output ->
...
output.setVersionCodeOverride(VERSION_CODE_INTEGER)
output.setVersionNameOverride(VERSION_NAME_STRING)
...
}
...
}
}