This is the error I get:
Flutter SDK not found. Define location with flutter.sdk in the local.properties file.
And this is what my file looks like currently, I'm not sure where to add this line because I'm completely new to flutter
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply from: project(':flutter_config').projectDir.getPath() + "/dotenv.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
If you are using android studio / intelij:
Go to Settings > Languages & frameworks > flutter > flutter SDK path
Then go to android/local.properties and add path again (create this file if it doesn't exist, if you are on windows, you should escape \ like this: C:\\Users\\user\\flutter):
Related
Hello I'm getting this error
FAILURE: Build failed with an exception.
Where:
Script 'D:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 713
What went wrong:
A problem occurred evaluating root project 'android'.
A problem occurred configuring project ':app'.
Could not create task ':app:compileFlutterBuildDebug'.
> Must provide Flutter source directory
text
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
defaultConfig {
// Required by the Flutter WebView plugin.
minSdkVersion 21
}
compileSdkVersion 33
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.food_app"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 20
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
manifestPlaceholders = [applicationName: "android.app.Application"]
}
debug {
manifestPlaceholders = [applicationName: "android.app.Application"]
}
build{
manifestPlaceholders = [applicationName: "android.app.Application"]
}
}
}
apply plugin: 'com.google.gms.google-services'
text 2
I try to build apk in my flutter application. I am got one warning and one error. Warning message : Your Flutter application is created using an older version of the Android embedding. It's being deprecated in favor of Android embedding v2.
Error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':app:debugRuntimeClasspath'.
> Failed to transform libs.jar to match attributes {artifactType=processed-jar, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: C:\Users\Abdulkadhar\Documents\Android\AppDevelopment\Production\simply2be_production\build\app\intermediates\flutter\debug\libs.jar.
> Transform's input file does not exist: C:\Users\Abdulkadhar\Documents\Android\AppDevelopment\Production\simply2be_production\build\app\intermediates\flutter\debug\libs.jar. (See https://issuetracker.google.com/issues/158753935)
* 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 4m 1s
Running Gradle task 'assembleRelease'... 243.1s (!)
Gradle task assembleRelease failed with exit code 1
Process finished with exit code 1
My app gradle
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '2'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "app.projects.xxx.xxxx"
minSdkVersion 19
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
flutter {
source '../..'
}
//apply plugin: 'com.android.application'
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-messaging:20.0.1'
implementation 'com.google.firebase:firebase-core'
}
apply plugin: 'com.google.gms.google-services'
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}}
My build gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'//4.0.0'//3.3.2 //3.5.3 //3.4.2
classpath 'com.google.gms:google-services:4.3.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
}
}
}
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}}
Here are my Gradle wrapper properties in case they are also important.
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
My gradle.properties
org.gradle.jvmargs=-Xmx1536m -Duser.country=US -Duser.language=en
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
build.gradle_pic1
build.gradle_pic2
build.gradle_pic3
build.gradle_pic4
I am trying to generate an appbundle. I've got a key.jks file already ready to go. As far as I know, I've followed Flutter.dev/AndroidDeployment correctly? This is my first app deployment. Is manually changing the build.gradle file the best way to go? I know there's a UI structure element that has drop menus and such in Android Studio that I've tried to no success. Anyways, like I said, all I've done is follow Flutter.dev on Android deployment and now I'm stuck and I think my issue lies somewhere within build.gradle considering that it always shows red error lines under it. Can someone take a look at what I've got and lead me in the right direction? I've changed the private parts for obvious reasons.
Thanks!
Here is the code:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with
flutter.sdk in the local.properties file.")`
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.changed_text.techhelprelease"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
signingConfig signingConfigs.release
}
signingConfigs {
release {
keyAlias keystoreProperties['key']
keyPassword keystoreProperties['changedText']
storeFile keystoreProperties['C:\\changedText\\key.jks'] ? file(keystoreProperties['C:\\changedText\\key.jks']) : null
storePassword keystoreProperties['changedText']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
The problem was this:
signingConfigs {
release {
keyAlias keystoreProperties['key']
keyPassword keystoreProperties['changedText']
storeFile keystoreProperties['C:\\changedText\\key.jks'] ? file(keystoreProperties['C:\\changedText\\key.jks']) : null
storePassword keystoreProperties['changedText']
}
}
Should have stayed default from Flutter.dev, which is this:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
And then I figured out that I must have accidentally pasted the signature line where it didn't belong, which was throwing me an error every time. So this:
defaultConfig {
applicationId "com.changed_text.techhelprelease"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
signingConfig signingConfigs.release
}
Should not have the last line. Corrected:
defaultConfig {
applicationId "com.changed_text.techhelprelease"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
}
How to define apk output directory when using gradle?
I would like to have possibility to upload apk to shared folder after each build.
thats work for me:
android.applicationVariants.all { variant ->
def outputName = // filename
variant.outputFile = file(path_to_filename)
}
or for Gradle 2.2.1+
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(path_to_filename, output.outputFile.name)
}
}
}
but "clean" task will not drop that apk, so you should extend clean task as below:
task cleanExtra(type: Delete) {
delete outputPathName
}
clean.dependsOn(cleanExtra)
full sample:
apply plugin: 'android'
def outputPathName = "D:\\some.apk"
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
applicationVariants.all { variant ->
variant.outputFile = file(outputPathName)
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
task cleanExtra(type: Delete) {
delete outputPathName
}
clean.dependsOn(cleanExtra)
I found the solution that works with the latest Gradle plugin:
def archiveBuildTypes = ["release", "debug"];
applicationVariants.all { variant ->
variant.outputs.each { output ->
if (variant.buildType.name in archiveBuildTypes) {
// Update output filename
if (variant.versionName != null) {
String name = "MY_APP-${variant.versionName}-${output.baseName}.apk"
output.outputFile = new File(output.outputFile.parent, name)
}
// Move output into DIST_DIRECTORY
def taskSuffix = variant.name.capitalize()
def assembleTaskName = "assemble${taskSuffix}"
if (tasks.findByName(assembleTaskName)) {
def copyAPKTask = tasks.create(name: "archive${taskSuffix}", type: org.gradle.api.tasks.Copy) {
description "Archive/copy APK and mappings.txt to a versioned folder."
print "Copying APK&mappings.txt from: ${buildDir}\n"
from("${buildDir}") {
include "**/mapping/${variant.buildType.name}/mapping.txt"
include "**/apk/${output.outputFile.name}"
}
into DIST_DIRECTORY
eachFile { file ->
file.path = file.name // so we have a "flat" copy
}
includeEmptyDirs = false
}
tasks[assembleTaskName].finalizedBy = [copyAPKTask]
}
}
}
}
For Gradle version 2.2.1 +, you can do this:
def outputPathName = "app/app-release.apk"
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(outputPathName)
}
}
This solution is work for classpath 'com.android.tools.build:gradle:3.1.2' and distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip. Put the following code inside your android scope of app-level build.gradle file. When you use command ./gradlew assembleDebug or ./gradlew assembleRelease, the output folder will be copied to the distFolder.
// Change all of these based on your requirements
def archiveBuildTypes = ["release", "debug"];
def distFolder = "/Users/me/Shared Folder(Personal)/MyApplication/apk/"
def appName = "MyApplication"
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (variant.buildType.name in archiveBuildTypes) {
// Update output filename
if (variant.versionName != null) {
String name = "$appName-${variant.versionName}-${output.baseName}.apk"
outputFileName = new File(name)
}
def taskSuffix = variant.name.capitalize()
def assembleTaskName = "assemble${taskSuffix}"
if (tasks.findByName(assembleTaskName)) {
def copyAPKFolderTask = tasks.create(name: "archive${taskSuffix}", type: org.gradle.api.tasks.Copy) {
description "Archive/copy APK folder to a shared folder."
def sourceFolder = "$buildDir/outputs/apk/${output.baseName.replace("-", "/")}"
def destinationFolder = "$distFolder${output.baseName.replace("-", "/")}"
print "Copying APK folder from: $sourceFolder into $destinationFolder\n"
from(sourceFolder)
into destinationFolder
eachFile { file ->
file.path = file.name // so we have a "flat" copy
}
includeEmptyDirs = false
}
tasks[assembleTaskName].finalizedBy = [copyAPKFolderTask]
}
}
}
}
I have this:
def loadProperties(String sourceFileName) {
def config = new Properties()
def propFile = new File(sourceFileName)
if (propFile.canRead()) {
config.load(new FileInputStream(propFile))
for (Map.Entry property in config) {
ext[property.key] = property.value;
}
}
}
loadProperties 'gradle.properties'
How do I reference the property (ndk.dir) in build.gradle?
def ndkBuild = new File("$ndk.dir", 'ndk-build')
And is there a better way of reading ndk.dir from file gradle.properties?
And how do I use it in?
def ndkBuild = new File("$ndk.dir", 'ndk-build')
Full code:
task buildNative(type: Exec) {
loadProperties 'gradle.properties'
if (System.getenv('NDK_HOME') != null || "$ndk.dir" != null) {
if ("$ndk.dir" != null) {
def ndkBuild = new File("$ndk.dir", 'ndk-build')
} else {
def ndkBuild = new File(System.getenv('NDK_HOME'), 'ndk-build')
}
workingDir "jni"
executable ndkBuild
} else {
throw new GradleException('Reason: NDK_HOME not set or ndk.dir is missing in gradle.properties...')
}
}
def loadProperties(String sourceFileName) {
def config = new Properties()
def propFile = new File(sourceFileName)
if (propFile.canRead()) {
config.load(new FileInputStream(propFile))
for (Map.Entry property in config) {
ext[property.key] = property.value;
}
}
}
Just like ndk.dir, "$ndk.dir" first gets the ndk property, and then the dir property, which is not what you want. (This is also evident in the error message, which says "Could not find property 'ndk'".) Instead, this should work:
def ndkBuild = new File(project.property('ndk.dir'), 'ndk-build')
A safer solution is to store the whole Properties object as a single extra property:
...
ext.externalProps = config
Then you can access external properties like so:
def ndkBuild = new File(externalProps['ndk.dir'], 'ndk-build')