17

I'm using Reactnative 0.54.0 and react-native-cli 2.0.1 along side gradle 4.8.1

I have created a react-native project using create-react-native-app myProjectName

When I created the project, it doesn't include android and ios folders, so I added them manually.

I also installed gradle using choco and then created a wrapper for it using gradle wrapper --gradle-version 4.8.1 --distribution-type all

so I am developing react-native using microsoft vsCode and then see my application in action using Genymotion emulator, everything is fine

now, I want to generate the final Signed APK for play store, I'm using this guide provided by react-native

https://facebook.github.io/react-native/docs/signed-apk-android.html

When I want to run gradlew assembleRelease I get this error

C:\myApp\android>gradlew assembleRelease

FAILURE: Build failed with an exception.

* What went wrong:
Task 'assembleRelease' 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. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s

what's wrong with assembleRelease? what should I do?

to add more info, I have to say that when I want to build this project in VSTS (TFS Online) I get this error

2018-07-17T16:20:14.9268702Z ##[error]Error: Not found wrapperScript: D:\a\1\s\gradlew

Any clue is appriciated Thanks

Update: as @philipp asked, this is the list of tasks that gradlew have listed and assembleRelease is not one one them!!!! what's the reason?

C:\myApp\Android>gradlew tasks

> Task :tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

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'.
dependentComponents - Displays the dependent components of components in root project 'android'. [incubating]
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'.

To see all tasks and more detail, run gradlew tasks --all

To see more detail about a task, run gradlew help --task <task>

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

and this is myApp\android**build.gradle**

project.ext.react = [
    bundleInStaging: true 
]
task wrapper(type: Wrapper) {
    gradleVersion = '4.8.1'
}
android {
    defaultConfig {
        applicationId "com.sunkime.client"
    }
    signingConfigs {
        staging {
            keyAlias = "staging"
            storeFile = file("my-release-key.keystore")
            keyPassword = "qwert%$#@!"
            storePassword = "qwert%$#@!"
        }
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword qwert%$#@!
                keyAlias qwert%$#@!
                keyPassword qwert%$#@!
            }
        }
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
        staging {
            applicationIdSuffix ".staging"
            signingConfig signingConfigs.staging
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }

        release {
            applicationIdSuffix ".release"
            signingConfig signingConfigs.release
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
}

I also used gradlew clean and no difference

Nasser Hadjloo
  • 12,312
  • 15
  • 69
  • 100

11 Answers11

11

Is it specific for assembleRelease or is gradlew assembleDebug working?

Maybe try cd android && ./gradlew clean && ./gradlew assembleRelease

Posting your apps build.gradle could also help.

As a first task I would recommend to run ./gradlew tasks to check if gradle is set up correctly and the task assembleRelease is listed.

Philipp
  • 468
  • 3
  • 24
  • 1
    I updated the question, and added **build.gradle** and a list of available **gradlew tasks**, assembleRelease is not listed!!!! I also used **gradlew clean** and no difference. do you have any idea, why assembleRelese is not listed? – Nasser Hadjloo Jul 18 '18 at 10:38
  • 1
    Maybe you are running `gradlew` from the wrong directory. You can also try using the `gradlew.bat` for Windows – Philipp Jul 18 '18 at 12:17
  • yes i wanna integrate it with bitrise as CI CD can anyone help on this – Faris Rayhan Jun 05 '20 at 19:41
5

You need a settings.gradle file into your Android folder.

scopchanov
  • 7,966
  • 10
  • 40
  • 68
Edu
  • 51
  • 1
5

If assembleRelease and assembleDebug tasks don't working, you can try gradlew assemble

Acuna
  • 1,741
  • 17
  • 20
4

That error can occur after upgrading versions of IntelliJ IDEA or Android Studio, or after Generating a new APK, you may need to refresh the IDE's cache. It can also be due to updating the location of SDK. Just a simple hack will do, Invalidate cache

File -> Invalidate Caches / Restart.
Ramesh R
  • 7,009
  • 4
  • 25
  • 38
Abednego
  • 599
  • 10
  • 17
2

I have finally solve this error:

You have to check, one by one each versions of your dependencies in your pubspec.yaml. During one week I got stuck bcs my version of path_provider package wasn't the latest.

bulgarian-beast
  • 367
  • 3
  • 10
1

For me works setting the ANDROID_HOME and delete file local.properties with "sdk.dir=C:\Users\Me\AppData\Local\Android\Sdk". When gradle does not find the local properties It search in ANDROID_HOME

1

Make sure you are not finding the android environment variables

Run the command on the mac like this to load the variables

source ~/.bash_profile
0

I encountered this error when I accidentally deleted app build.gradle file.

Cembora
  • 244
  • 2
  • 15
0

File -> Invalidate Caches / Restart... does magic

ENT108
  • 1
  • 1
0
"createAndroidBuild" : "cd android && ./gradlew clean && ./gradlew assembleRelease"

In terminal run this script using below command

yarn createAndroidBuild

enter image description here

Sourabh Gera
  • 862
  • 7
  • 7
0

for me I remove : before assemble
this throw error

./gradlew clean :assembleRelease

solved by

./gradlew clean assembleRelease
Tuan Dat Tran
  • 425
  • 5
  • 7