'installDebug' not found in root project 'android' React Native - android

I am trying to run my project on the android simulator. When I run react-native run-android I am getting the following:
FAILURE: Build failed with an exception.
* What went wrong: Task 'installDebug' not found in root project 'android'.
* Try: Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
If I run ./gradlew tasks I get:
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'android'.
components - Displays the components produced by root project 'android'. [incubating]
dependencies - Displays all dependencies declared in root project 'android'.
dependencyInsight - Displays the insight into a specific dependency in root project 'android'.
help - Displays a help message.
model - Displays the configuration model of root project 'android'. [incubating]
projects - Displays the sub-projects of root project 'android'.
properties - Displays the properties of root project 'android'.
tasks - Displays the tasks runnable from root project 'android'.
Any idea why I don't have a installDebug task in my project? How do I get it back?

react-native run-android --variant [productFlavorName][debug/release]
e.g.
react-native run-android --variant Huaweidebug

For Debug test
react-native run-android --variant devKernelDebug
The reasons is because in the file android/build.gradle we have this
productFlavors {
devKernel {
dimension 'remoteKernel'
}
prodKernel {
dimension 'remoteKernel'
}
}

i had the same issue in fresh react-native project (react-native init projectname) after running react-native start then react-native run-android in VS code. It gave this error
Task 'installDebug' not found in project ':app'.
It is in RN "0.62.1"
Solution:-
i open Android Studio, then clean and rebuild.
I am not sure would it work after clean and rebuild.
i also did and gave the sdk path in root project
export ANDROID_HOME=/home/mycomputer/Android/Sdk/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Then it works.
My npm version 6.7.0
My Node version v11.10.1
react-native-cli: 2.0.1
react-native: 0.62.1

I was also having this issue with one more issue
Deprecated Gradle were used in this build, making it incompatible with
Gradle 7.0.
in Android build as the screenshot attached.
On opening the android folder with android studio and letting it build by android studio, the problem is getting fixed. After that on running
npx react-native run-android
, it is working fine.

I have solved this problem You just need to Create file in Android Folder
Go android folder
Create file local.properties
then just add this code in local.properties file:-
If you are using MacBook then sdk.dir=/Users/USERNAME/Library/android/sdk
if you are using Windows then sdk.dir=C:\Users\USERNAME\AppData\Local\Android\sdk
if you are using Linux then sdk.dir = /home/USERNAME/Android/sdk
if you want to know what is your system USERNAME then just use command for Mac whoami
and then just rerun command react-native run-android
Thanks :)

cd android
./gradlew clean
cd..
react-native run-android --variant=DevDebug
This fixed for me

The error comes when the project is constructed on flavors.
Flavors is the solution when you need to build the same app but for different clients, like one for Facebook and one for Microsoft, and you have to do some minor adjustments to your code. More about flavors here: https://blog.logicwind.com/adding-multiple-target/
So, to solve this, for the Android system, go to android/app/build.gradle
Now find the next part:
android {
...
flavorDimensions "default"
productFlavors {
dev {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.myproject.dev'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
}
prod {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.myproject'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
}
facebook {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.myproject.facebook'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
}
}
defaultConfig {
applicationId "com.myproject"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
...
}
As you can see in the productFlavors tag we have 3 different builds (dev, prod and facebook). Now, each of those flavors have two different runtime modes (or builds) (Debug and Release). So, as others suggested, when you build your app, you will have to specify the flavor you want to build.
The command you will need to use is next:
npx react-native run-android --variant <productFlavour><BuildType>
Looking up at the build.gradle, for this project we have the next possible variants:
devDebug and devRelease,
prodDebug and prodRelease,
facebookDebug and facebookRelease
Depending on your configuration, just adjust the productFlavor and you are good to go

Following steps worked for me:
Right click the "android" folder and click "Open in Integrated Terminal"
Run "gradlew tasks" command.
Scroll down to "Install tasks" section:
The list will contain the variants which you will pass against the run-android command. Taking for instance the "installExperimentalFossDebug" task, the variant will be "ExperimentalFossDebug".
Next step is to run the "run android" command at the root of the project (not in the android folder) with that variant.
npx react-native run-android --variant ExperimentalFossDebug
Following the above steps you will be able to run the project against emulator:

just change this,go to this folder and file,
node_modules/react-native/local-cli/runAndroid/runAndroid.js
replace installdebug with
} else {
gradleArgs.push('installDevDebug');
}

Below command solved my issue:
Run--> gradlew :app:installDebug inside ./android folder
After installation run gradlew tasks to list down the tasks available. There you can check
Install tasks
installDebug - Installs the Debug build.
installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build.
uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
uninstallRelease - Uninstalls the Release build.

I know this is an old question, but just in case : had the same trouble today with a react-native project, juste double check that your ANDROID_HOME environment variable is set to your local SDK folder.
You may try "react-native doctor" to see what's happening; but it make sense : without ANDROID_HOME, react-native just doesn't know what to build, so you can't run anything.

Open the project with android studio, it will automatically fix the issues

I had the same issue with react native. Finally able to solve the issue by following the exact environment set guideline in the rest-native documentation. Go through the documentation in the URL below. Good luck.
enter link description here

The error comes when the project is constructed on flavors
i was writing npx react-native run-android -variant=devDebug which was causing an issue but as soon as i write npx react-native run-android --variant devDebug it is working fine for me.
working on windows laptop

I am pasting the code to show some of the available options for run-android
var _default = {
name: 'run-android',
description: 'builds your app and starts it on a connected Android emulator or device',
func: runAndroid,
options: [{
name: '--root [string]',
description: 'Override the root directory for the android build (which contains the android directory)',
default: ''
}, {
name: '--variant [string]',
description: "Specify your app's build variant",
default: 'debug'
}, {
name: '--appFolder [string]',
description: 'Specify a different application folder name for the android source. If not, we assume is "app"',
default: 'app'
}, {
name: '--appId [string]',
description: 'Specify an applicationId to launch after build.',
default: ''
}, {
name: '--appIdSuffix [string]',
description: 'Specify an applicationIdSuffix to launch after build.',
default: ''
}, {
name: '--main-activity [string]',
description: 'Name of the activity to start',
default: 'MainActivity'
}, {
name: '--deviceId [string]',
description: 'builds your app and starts it on a specific device/simulator with the ' + 'given device id (listed by running "adb devices" on the command line).'
}, {
name: '--no-packager',
description: 'Do not launch packager while building'
}, {
name: '--port [number]',
default: process.env.RCT_METRO_PORT || 8081,
parse: val => Number(val)
}, {
name: '--terminal [string]',
description: 'Launches the Metro Bundler in a new window using the specified terminal path.',
default: (0, _cliTools().getDefaultUserTerminal)()
}, {
name: '--tasks [list]',
description: 'Run custom Gradle tasks. By default it\'s "installDebug"',
parse: val => val.split(',')
}, {
name: '--no-jetifier',
description: 'Do not run "jetifier" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don\'t support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.',
default: false
}]
};
I hope the answer is helpful

The solution is simple-
Open the react-native app's android folder in Android studio.
Select the app folder and click on Menu -> Build -> Re-build.
If it asks for updates or some recommended actions, accept them all.
MOST IMPORTANT, modify the permission of the gradlew.bat file. To do so, open the react-native app in the terminal and run-
chmod +x android/gradlew.bat
And then finally run-
npx react-native start
npx react-native run-android

The following command solved the problem for me on Linux. You should replace ~/Android/Sdk with your own Android SDK path.
export ANDROID_SDK_ROOT=~/Android/Sdk

Open you React Native project's android folder in Android Studio, for me it automatically generated
local.properties
which contains the sdk.dir
Then go back to the root of your React Native project and run
yarn android

I got the same error. I just opened the VS Code and inside the android folder, I created local.properties file and then added sdk.dir=/Users/apple/Library/Android/sdk(Don't copy mine you can find your sdk path in android studio). Later, I ran npx react-native run-android and this solved my problem.

You must run gradlew in the android directory.
Here’s an example. Run the following command and it will produce the same output the OP mentioned.
./android/gradlew tasks
Then try:
cd android
./gradlew tasks
The output is wildly different. I don't know why this is the case.

Open Android folder in the Android studio then it will download all required files automatically

Remove productFlavors code from android/app/build.gradle

Related

Deprecated Gradle features were used in this build after setting target api to 31 [duplicate]

I've got a gradle FAILURE:
..."Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0."
Case description:
Attached to the project codebase the next libs:
APP/build.gradle
//(Required) Writing and executing Unit Tests on the JUnit Platform
testImplementation "org.junit.jupiter:junit-jupiter-api:5.2.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.2.0"
// (Optional) If you need "Parameterized Tests"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.2.0"
// (Optional) If you also have JUnit 4-based tests
testImplementation "junit:junit:4.12"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.2.0"
testImplementation "io.mockk:mockk:1.8.5"
Updated the gradle-wrapper.properties
distributionUrl=https....gradle-4.4-all.zip to 4.7-all
after all of that gradle was built success
created the test calss
#TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestClass {
#Test
internal fun testName() {
Assert.assertEquals(2, 1 + 1)
}
}
ran the test and got the FAILURE message.
ran the Gradle build with a command line argument ./gradlew --warning-mode=all to see what exactly the deprecated features are.
As a result I couldn't build the app and I've got that FAILURE: message.
Run the Gradle build with a command line argument --warning-mode=all to see what exactly the deprecated features are.
It will give you a detailed description of found issues with links to the Gradle docs for instructions how to fix your build.
Adding --stacktrace to that, you will also be able to pinpoint where the warning comes from, if it's triggered by outdated code in one of the plugins and not your build script.
Try this one
cd android && ./gradlew clean && ./gradlew :app:bundleRelease
The process below worked in my case-
First check Gradle Version:
cd android
./gradlew -v
In my case it was 6.5
Go to https://developer.android.com/studio/releases/gradle-plugin and you'll get the plugin version for your gradle version. For gradle version 6.5, the plugin version is 4.1.0
Then go to app/build.gradle and change classpath 'com.android.tools.build:gradle:<plugin_version>
My project was incompatible with Gradle 8.0 .Here's what worked for me:
First I wrote this line of code in the Android Studio terminal:
./gradlew build --warning-mode all
When you do that, you will be shown in the logcat what is found to be deprecated or an issue in your project, for me it was the jcenter() repository that needed to be removed in my settings.gradle file and also I needed to update classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21" to classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30" in my build.gradle project file.
Once I did these things, my project built perfectly and installed on my emulator
I was getting this error. Turns out it only happened when I completely cleaned the RN caches (quite elaborate process) and then created a release build.
If I cleaned the caches, created a debug build and then a release build, everything worked. Bit worrying but works.
Note: My clean command is...
rm -r android/build ; rm -r android/app/src/release/res ; rm -r android/app/build/intermediates ; watchman watch-del-all ; rm -rf $TMPDIR/react-* ; npm start -- --reset-cache
Important - Answer work only for REACT-NATIVE VS CODE Terminal
In VisualStudio code, you have to run like below then that warning will be omitted.
react-native run-android warning-mode=all
If you run below then you will get the error in terminal
When running react-native run-android --warning-mode all I get error: unknown option --warning-mode'
in my case i updated the build.gradle file and make the classpath to latest version from 3.5.2 to 3.6.3
dependencies {
classpath("com.android.tools.build:gradle:3.6.3")
}
In my case adding multiDexEnabled true in Android/app/build.gradle file compiled the files.
I will look into removing this in the future, as in the documentation it says 'Before configuring your app to enable use of 64K or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or included libraries.'
defaultConfig {
applicationId "com.peoplesenergyapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true // <-add this
}
The following solution helped me as I was also getting the same warning.
In your project level gradle file, try to change the gradle version in classpath
classpath "com.android.tools.build:gradle:3.6.0" to
classpath "com.android.tools.build:gradle:4.0.1"
Update your third party dependencies. for example I updated dependency from
implementation 'com.github.ybq:Android-SpinKit:1.1.0' to implementation 'com.github.ybq:Android-SpinKit:1.2.0'. and in my case issue has been solved.
It work for me in this issue in a project of react-native:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
244 actionable tasks: 2 executed, 242 up-to-date
D8: Cannot fit requested classes in a single dex file (# fields: 67296 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
....
I Did this:
Uninstall the app from my device:
The number of method references in a .dex file cannot exceed 64k API 17
Set distributionUrl path in gradle-wrapper-properties files as :
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
Solution for the issue:
deprecated gradle features were used in this build making it incompatible with gradle 6.0. android studio
This provided solution worked for me.
First change the classpath in dependencies of build.gradle of your project
From: classpath 'com.android.tools.build:gradle:3.3.1'
To: classpath 'com.android.tools.build:gradle:3.6.1'
Then make changes in the gradle-wrapper.properties file this file exists in the Project's gradle>wrapper folder
From: distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
To: distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Then Sync your gradle.
Uninstall the old app from the device/emulator. It worked for me
i'am using react-native and this works for me :
in root of project cd android and gradlew clean
open task manager in windows
on tab 'Details' hit endtask on both java.exe proccess
long story short
> Task :app:installDebug FAILED Fixed by kiling java.exe prossess
Solved this issue by deleting the .gradle folder from /android and again run npm run android, and it solved this error.
Here's a link to the issue: https://github.com/facebook/react-native/issues/28954
I am using react-native if all above didn't work delete Build and .gridle folder inside the Android folder and run again, That solved my problem
Go to gradle/wrapper/gradle-wrapper.properties change the distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip to the release that is needed (or higher).
Then run again cd android && ./gradlew bundleRelease
Finally decided to downgrade the junit 5 to junit 4 and rebuild the testing environment.
On a SpringBoot project using IntelliJ and Gradle, I got the warning "Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0" when running my integration test.
What solved the problem was:
- Going to: File > Settings > Build, Execution, Deployment
- Selecting for "Build and run using": Intellij IDEA (instead of "Gradle")
- Same for "Run tests using"
That did not explain why Gradle is displaying the warning, but that let me perform the test and progress in my work.
I found my disk space is less than 4 GB and can not get the Gradle lib repo
then show
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
just remove tmp and junk files, free up space then try build and resolve problem
In my case deleting the whole android folder from the base directory and allowing it to rebuild all of it on eas build fixed this error for me :)
1)cd android
2) ./gradlew clean
3)./gradlew :app:bundleRelease
then last install npm install command
it is due to incompatibility.
please upgrade classpath("com.android.tools.build:gradle:4.0.1") in build.gradle file under android folder.
Check settings.gradle script and remove jcenter() from that it may be causing the issue as it is deprecated.
You're new settings.gradle file should be
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
plugins {
id 'com.android.application' version '7.1.0-alpha12'
id 'com.android.library' version '7.1.0-alpha12'
id 'org.jetbrains.kotlin.android' version '1.5.21'
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "ComposePlayground"
include ':app'
Take note that ComposePlayground is app name.
I Sloved this problem by updating my gradle-wrapper.properties file. You have to change this line distributionUrl=https://services.gradle.org/distributions/gradle-7.3.3-bin.zip to the lates gradle build which can be found at The Gradle Wrapper.
Hope that helps someone out there :)
After none of the above answers worked for me, I managed to solve this issue by upgrading the Gradle plugin to the latest version and using the JDK 11.
Hope this helps someone!
Try this solution worked for me.
If you have another app with the same name (or package name) on the device: Rename the app or delete it from your device.
For me, the problem was that I ran out of space in my device's internal storage. After deleting a few unnecessary apps, it worked fine.
After hours of searching on the web I used this command:
react-native run-android warning-mode=all
on vs code.
And it turns out that the error have nothing to do with deprecated modules or any gradle error, it was just that my device was full of storage.
I hope it will help someone one day.

Installing WatermelonDB from github gives "Unable to resolve module #nozbe/watermelondb/adapters/sqlite"

I am trying to compile a hello-world react-native app that has WatermelonDB configured. I am following the instructions given here and and here to set up the project for Watermelon.
I have found that if I install WatermelonDB using
yarn add #nozbe/watermelondb
the application launches correctly in android and iOS. But if I install from github:
yarn add https://github.com/Nozbe/WatermelonDB.git
I get the following error:
Does anyone know why installing directly from github results in this error when running the application?
Add these lines in android/app/build.gradle
android {
defaultConfig {
...
minSdkVersion 21 // add this
multiDexEnabled true // add this
}
}
add this in dependencies
implementation 'com.android.support:multidex:1.0.3'
then sync after that
clean the project, build folder, gradlew and idea
cd android
./gradlew clean
also
rm -rf .gradle && rm -rf .idea

NDK is not installed

When building a flutter app, I get an error stating
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:extractReleaseNativeDebugMetadata'.
> NDK is not installed
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 822ms
However, the android NDK is installed.
I had the same issue. I wanted to extract the debug symbols for better debugging in the production environment.
Solution
Step 1: Installing NDK and CMAKE SDK tool from android studios (You can skip it, if already installed)
Open any project in Android studio. (Doesn't matter which project. We just want to access SDK manager)
With a project open, click Tools > SDK Manager.
Click the SDK Tools tab.
Select the NDK (Side by side) and CMake checkboxes.
Image of SDK Manager
Click OK.
A dialog box tells you how much space the NDK package consumes on disk.
Click OK.
When the installation is complete, click Finish.
Step 2
1. Check which version of NDK is installed in your system.
To check, find the NDK folder inside the Android SDK folder. For mac users, it is located at - ~/Library/Android/sdk/ndk/
You will find a folder with the NDK version name inside this directory.
For example - in my case, the installed NDK version was 23.0.7599858. So, I was able to find this directory at this location ~/Library/Android/sdk/ndk/23.0.7599858/
Note: For Ubuntu or windows users sdk/ndk directory's location will be different.
2. Ensure you have the same NDK version mentioned in the android/build.gradle file.
buildscript {
ext {
...
ndkVersion = "23.0.7599858" # the installed version of ndk.
}
...
}
EDIT:
Make sure you have ndkVersion initialized in the app/build.gradle
like this:
android {
...
ndkVersion rootProject.ext.ndkVersion
...
}
Or you can also directly write the version here like this:
android {
...
ndkVersion "23.0.7599858"
...
}
You don't have to add the ndkVersion in android/build.gradle if you do this.
Using android studio open
a. Go to settings, System settings, android sdk,on the tabs select SDK Tools confirm if NDK (side by side) and CMake Tool are installed
b. If not installed check them and press apply to download and install them.
After successfull confirmation. Open your project android folder find local.properties file, android/local.properties. You will find Something like this
Add your NDK path as follows
To find yoour NDK path
Go to home files if linux, android folder, sdk folder, inside find ndk folder, ie
/Android/Sdk/ndk/24.0.8215888
Happy Coding ! ! !
I got that error on React Native 0.64 app on AppCenter build for Android.
The solution is to go to android/app/build.gradle file and comment ndk { debugSymbolLevel 'FULL' } line if you have so (defaultConfig { ndk { debugSymbolLevel } })
The solution was found by my colleague Jose, so all credits to him)
After I added
ndk {
debugSymbolLevel 'FULL'
}
in app build.gradle file I got this error about NDK not installed.
I resolved the same problem by making this change in main build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
...
}
This Gradle upgrade forced me to upgrade the url in gradle/wrapper/gradle-wrapper.properties file
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
I have Android Studio Bumblebee 2021.1.1 Patch 3
I have only installed ndk from the android studio and
My problem just got solved, After including ...
local.properties
ndk.dir=<ANDROID_SDK>\\ndk\\XX.X.XXXXXXX
android/app/build.gradle
android {
// ...
ndkVersion "XX.X.XXXXXXX"
// ...
buildTypes{
release{
signingConfig signingConfigs.release
ndk {
debugSymbolLevel 'SYMBOL_TABLE'
}
}
}
}
This could help someone and save his/her time.
If you are using Flutter Please use this approach(according to your ndk version from checkin android studio),
it solved my problem and I used it for debug symbols native crashes
android {
...
ndkVersion "23.0.7599858"
...
}

How to execute UI tests for a Dynamic Feature Module via Android Studio?

I have a regular :app module and a DFM :feature.
I place the tests for the DFM in androidTest source set inside :feature.
When I try to launch the test using run configuration created by Android Studio it silently fails with Test framework quit unexpectedly.
If I launch the test through the terminal with the command displayed by Android Studio in Run tab I will see:
$ adb shell am instrument -w -m -e debug false -e class 'com.amazing.feature.AmazingTest' com.amazing.application.test/com.amazing.feature.TestRunner
...
Unable to find instrumentation info for: ComponentInfo{com.amazing.application.test/com.amazing.feature.TestRunner}
Which is not surprising, since the path to the runner is different:
$ adb shell pm list instrumentation
instrumentation:com.amazing.feature.test/com.amazing.feature.TestRunner (target=com.amazing.application)
The test works if I use that instrumentation on the commandline.
Is there a way to teach Android Studio do that?
I got this issue as well, just after upgrading to AGP 7 and the latest Android Studio. In my case it was a bit different, I have the same repository checked out twice, so work on 2 branches simultaneously. In my case, it happened that one branch + android studio instance would work, it did select the correct TestRunner, and the other instance did not work. This lead me to the simple solution of:
Build -> Clean Project
Remove any remaining build folders (was just 1 for me)
Then retry and it did select the correct TestRunner.
Other things ive tried, of which I do not know whether or not they helped, are the following:
Make sure I use Java 11 (since i'm on AGP 7)
Project Structure -> Gradle settings -> Gradle JDK should be something like 11
Disable the experimental feature Do not build Gradle task list during Gradle sync (automatically enabled on Android Studio Arctic Fox)
I had the same issue. Turns out gradle creates a wrong targetPackage in the <instrumentation> tag in the dynamic feature module's AndroidManifest.xml of the androidTest APK. You can fix this by setting the testApplicationId in the module's build.gradle defaultConfig.
defaultConfig {
testApplicationId 'com.amazing.feature.test' // Set the test package here!
testInstrumentationRunner 'com.amazing.feature.TestRunner'
[...]
}
More documentation on this on developer.android.com.

Building Android Studio project on Jenkins? android.compileSdkVersion is missing

I'm trying to set up my first Android project to build on Jenkins.
I'm running Jenkins 1.6.2 with version 1.24 of the Gradle plugin. Running on Windows 7 Professional SP1.
I've installed Android Studio and the Java7 JDK on my build machine, and a checked-out version of the software builds just fine, through Android Studio or when running gradlew.bat from the command line. But I can't get the Invoke Gradle script build task to work, within my Jenkins job.
There is a pair of radio buttons, on the configure project page:
Invoke Gradle
Use Gradle Wrapper
If I select "Invoke Gradle", I'm asked to select a "Gradle Version", which is something I setup in Configure System.
I created a gradle installation with GRADLE_HOME set to "D:\Program Files\Android Studio\gradle\gradle-2.2.1". That gives me a warning that "D:\Program Files\Android Studio\gradle\gradle-2.2.1 is not a directory on the Jenkins master...."
And when I run a build, I get an error "Can't retrieve the Gradle executable".
Which is probably related to the gradle plugin complaining about the directory. But the directory is correct. I've tried it with '/' instead of '\', and it made no difference.
Since that didn't work, I tried the alternative, "Use Gradle Wrapper". There's a checkbox: "From Root Build Script Dir". Whether I check it, or not, I get "java.lang.IllegalArgumentException: android.compileSdkVersion is missing!"
I've set both JAVA_HOME and ANDROID_HOME, so that's not the issue.
Any ideas?
As a followup, I delete the gradle task, and added an Execute Windows batch command task:
SET ANDROID_HOME=d:\Program Files\Android\sdk
SET JAVA_HOME=d:\Program Files\Java\jdk1.7.0_79
.\gradlew.bat clean
When I run that, I still get that error.
But when I run those commands from a command line on the build machine, they work just fine.
What could be different, when running gradlew.bat from Jenkins, than when running it from the command line? The Jenkins service is configured to use the same user as I'm logged in as, when I'm running from the command line. I've tried explicitly setting each and every environment variable I have set in the command line, in the Jenkins task, and I'm still seeing the error.
Any ideas?
Your local.properties file must contain:
sdk.dir="path to your android sdk"
I'm also using jenkins for building my apps and had a similar problem.
I fixed it by executing the gradle wrapper via jenkins without using the jenkins gradle plugin.
cd $WORKSPACE
./gradlew assembleRelease
And if you want lint add a second shell exec with
cd $WORKSPACE
./gradlew lint
Note that these commands are for a linux system but they will work just fine on windows (had a windows build server some time ago and did the same thing)
I met this problem too, but I don't know whether my solution suit for you.
My situation is below, in my project build.gradle file:
apply plugin: 'com.android.library'
apply from: 'maven_push.gradle'
dependencies {
......
}
android {
compileSdkVersion 19
buildToolsVersion "21.1.0"
......
}
When i run: gradle clean build, error message show:
* Where:
Script 'C:\xxxxxx\Project\maven_push.gradle' line: 32
* What went wrong:
A problem occurred evaluating script.
> android.compileSdkVersion is missing!
My solution is change the position of this script apply from: 'maven_push.gradle' to the bottom in build.gradle file, and BUILD SUCCESSFUL!:
apply plugin: 'com.android.library'
dependencies {
......
}
android {
compileSdkVersion 19
buildToolsVersion "21.1.0"
......
}
apply from: 'maven_push.gradle'
I think you should pay attention to the "Where" message in the error command line.
I can't be sure it's gonna solve your issue, but maybe you can consider using the sdk-manager-plugin which downloads and installs the android sdk directly from gradle.
If it works, it probably won't tell you why your current configuration is not working, but at least you won't be stuck anymore.

Categories

Resources