"Neither path nor baseDir may be null or empty string." error when importing gradle project in Android Studio 0.2.9 - gradle

NOTE: i can't post links, so i guess you'll need to go here to follow the references. sorry, not my rule.
i'm getting the following error when attempting to import a project into Android Studio 0.2.9:
Could not execute build using Gradle distribution
'http://services.gradle.org/distributions-snapshots/
gradle-1.8-20130830160653+0000-bin.zip'.
A problem occurred configuring project ':library'.
A problem occurred configuring project ':library'.
Failed to notify project evaluation listener.
Neither path nor baseDir may be null or empty
string. path='' basedir='<projects folder>/
drag-sort-listview/library'
Consult IDE log for more details (Help | Show Log)
the project was originally a Maven project (1). i opened it in Eclipse ADT, generated a /librabry/build.gradle file per the instructions at (2).
the Eclipse ADT generated build.gradle looked like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 7
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['']
resources.srcDirs = ['']
aidl.srcDirs = ['']
renderscript.srcDirs = ['']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
i had to change line 6 from
classpath 'com.android.tools.build:gradle:0.4'
to
classpath 'com.android.tools.build:gradle:0.5+'
to get Android Studio to stop saying the versions were miss-matched. i also added a /settings.gradle file containing
include ':library'
and a /local.properties file with the contents
# This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=/Applications/Android Studio.app/sdk
i then attempted to import the /settings.gradle file by selecting it in the 'File | Import Project...' dialog. i have 'Use Auto-import' checked and 'Use gradle wrapper with verification' option selected in the dialog (3). the full idea.log entry can be viewed at (4).
any help would be greatly appreciated, thanks.

This will happen if you are using Environment Variables like so:
android {
signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
And you have not defined those variables in your gradle.properties file located at the root of your project.
To fix this, make sure your variables are defined, here is an example from my gradle.properties file:
RELEASE_STORE_FILE=app_keystore.jks
RELEASE_STORE_PASSWORD=password
RELEASE_KEY_ALIAS=MyAppKey
RELEASE_KEY_PASSWORD=password

The error may be referring to your keystore's path. If the keystore's path doesn't work, it will think it's null. If you just want to use your keystore's file name (instead of the full path), make sure the keystore is in the root directory of your project.
android {
signingConfigs {
release {
storeFile file(**DoubleCheckPath**)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}

(Answered by the OP in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
ok, solved it. the issue is with the empty lists under android.sourceSets in build.gradle, I commented them out to resolve the error. Here's my current build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 7
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
// java.srcDirs = ['']
// resources.srcDirs = ['']
// aidl.srcDirs = ['']
// renderscript.srcDirs = ['']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
hope that helps y'all.

you may miss a file in project, for "gradle.properties" file, because this file is include some varies, for example , our custom var, such key.storefile key.keypassword, you should check this file is exists or not.

Modify file(String.valueOf(RELEASE_STORE_FILE)) in
android {
signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}

Related

How to add a dependency to build.gradle.kts for kotlin-multiplatform (kotlin 1.3.50)?

I started a new project with kotlin-multiplatform to create a library usable on iOS and Android using this tutorial :
https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/01_Introduction
It seems to work fine but I wanted to add the Serialization library mentioned at the end of the tutorial (https://github.com/Kotlin/kotlinx.serialization) and I can't make it work.
The setup guide in the library is not in Kotlin DSL so I tried different things to adapt the code but without success. Here is my project gradle :
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And now my build.gradle.kts
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "SharedCode"
}
}
}
jvm("android")
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.13.0")
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.13.0")
}
sourceSets["iosMain"].dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.13.0")
}
}
val packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")
/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets
.getByName<KotlinNativeTarget>("ios")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from({ framework.outputDirectory })
into(targetDir)
/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText("#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$#\n")
gradlew.setExecutable(true)
}
}
tasks.getByName("build").dependsOn(packForXcode)
I have no errors but I cannot use the library in my code.
Can someone please explain how to integrate this dependency or any dependency with this setup ? What do I do wrong ?
Note : I'm using Android Studio 3.5.1, Gradle 5.4.1, Kotlin 1.3.50.
Ok, so I found the issue.. just the version of the library.. 0.13.0 not 0.14.0. No error is thrown when you sync a wrong library version. I hope this post helps someone anyway.

Adding external source files to a kotlin project

I have Kotlin sources located at, say, repo/project_a/src/. I created a Kotlin Gradle project in IntelliJ IDEA, located at repo/project_b/.... And I can't for the life of me figure out how to add the sources. If I add them through project structure menu it works fine, but as soon as it wants to re-read the gradle file id deletes the structure (It warns as much in the UI).
This is my gradle file:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.2.70'
}
group 'cli'
version '1.0'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
I've tried adding all variations of
sourceSets {
main {
kotlin {
srcDirs += "repo/project_a/"
}
}
}
But it does absolutely nothing.
Any ideas?
The path you are giving to Gradle will compile to the current project path plus "repo/project_a/". Try with:
sourceSets {
main {
kotlin {
srcDirs += "../project_a/"
}
}
}

How do I add debug/release specific generated source to Android Gradle?

I have the following sourceSet entry. Each directory contains the autogenerated java source files, which should be compiled for each respective debug/release build.
sourceSets {
debug {
java.srcDirs = [generatedDebugCodeDir]
}
release {
java.srcDirs = [generatedReleaseCodeDir]
}
}
However, I do not see the directories added to the classpath (by using the --debug Gradle flag). How should I address this? I tried java.srcDir (no S), which is not even recognized.
One workaround I'm considering is just generating the files in the appropriate generated buildConfig dirs. Hopefully there's no crazy side effect.
Turns out, it will be better for me to use the flavor specific java.srcDirs. This setup worked for me.
flavor1Debug{
java.srcDirs = ["${generatedJavaDirRoot}/flavor1/debug/"]
}
flavor1Release{
java.srcDirs = ["${generatedJavaDirRoot}/flavor1/release/"]
}
flavor2Debug{
java.srcDirs = ["${generatedJavaDirRoot}/flavor2/debug/"]
}
flavor2Release{
java.srcDirs = ["${generatedJavaDirRoot}/flavor2/release/"]
}

Android Studio: Library not recognizing the Android API

I am trying to add this library to my project. I put the files from GitHub in my libraries directory under my project's default module folder.
When I first added the library, it wasn't recognized in my project until I changed the the folder structure from httpzoid/src/ to httpzoid/src/main/java.
At this point I am able to import classes from the library. The only problem is, Android components such as android.content.Context aren't recognized by the library, so it basically doesn't work.
The project does not have a Ant or Gradle build file so need to create one.
First you will need to delete the local.properties since it references the developers local sdk directory. Then create a file named build.gradle in the projects directory with the following content.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android-library'
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
compileSdkVersion 19
buildToolsVersion "19.0.3"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
}
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
}
Then in command line go to the projects root directory and run "gradle build". This will generate the file "Httpzoid.aar" in the projects build/libs directory. Copy this file into your main project's libs folder.
You'll now be able to add it as a dependency by modifying your project's build.gradle file and adding the following:
dependencies {
repositories {
flatDir {
dirs 'libs'
}
}
compile(name:'Httpzoid', ext:'aar')
}
As an aside, have you considered using Retrofit or Ion as an alternative REST client? These two excellent libraries have similar callback mechanisms and both are actively updated (Last update for HttpZoid was July 22, 2013). Also they are both on Maven Central.

Android Gradle Build Resource.getIdentifier() always returns 0

I'm getting started on porting my Game over to the new Gradle Build system for Android.
I'm using the Resource.getIdentifier() method to load some resources by name instead of ID. However, ever since switching to the Gradle build, this call always returns 0. The assets are included in the built jar, and the R.class in the dex file contains all of my resources and ID's as expected, so I am at a loss as to explain this. This code worked before I changed to the gradle build. My build.gradle is below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:18.0.+'
}
android {
compileSdkVersion 18
buildToolsVersion "19"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
buildTypes {
debug {
packageNameSuffix ".debug"
}
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
TIA.
D'oh! my problem was that Resources.getIdentifer() takes 3 parameters, one of which is the package name. The debug section of my gradle script was tacking on ".debug" to the package name on the device. Solution is to remove the .debug suffix in the build.gradle.

Resources