NanoHTTPD - unable to add gradle dependency - android

I am trying to add NanoHTTPD to my Android project.
As mentioned in README.md, I added
dependencies {
runtime(
[group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1'],
)
}
it is giving error:
Could not find method runtime() for arguments [{group=org.nanohttpd, name=nanohttpd, version=2.3.1}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I also tried adding
repositories {
mavenCentral()
}
mentioned elsewhere, but same error.
I tried the usual way:
implementation 'org.nanohttpd.nanohttpd:2.3.1'
it gives error:
Failed to resolve: org.nanohttpd.nanohttpd:2.3.1:
I am using Android Studio 3.2.1
There seem to be so many people happily using it in Android. What am I missing?

In your gradle file, separate group and artifact ids with a : instead of .. That is, replace
implementation 'org.nanohttpd.nanohttpd:2.3.1'
with
implementation 'org.nanohttpd:nanohttpd:2.3.1'

Related

Gradle build fails saying : Could not find org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:0.3.3

I'm building a new project using Android Studio Canary and while setting up dependencies for jet pack compose I get this as build output:
Execution failed for task ':app:processDebugAndroidTestManifest'.
> Could not resolve all files for configuration ':app:debugAndroidTestRuntimeClasspath'.
> Could not find org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:0.3.3.
Required by:
project :app > androidx.compose.runtime:runtime:1.0.0-beta02
enter image description here
Add jcenter to the repositories of your settings.gradle file.
You can specify that it should only be used for this missing artefact.
It should look like this:
repositories {
google()
mavenCentral()
//noinspection JcenterRepositoryObsolete
jcenter {
content {
includeModule("org.jetbrains.kotlinx", "kotlinx-collections-immutable-jvm")
}
}
}
Try adding jcenter() to your repositories. It's being phased out and you'll get a warning, but at the moment it is the only solution. See this:
https://github.com/ReKotlin/ReKotlin/issues/47
and https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ : "To clarify, the JCenter repository will keep serving packages for 12 months until February 1st 2022. Only the JCenter REST API and UI will be sunsetted on May 1st 2021."
Based on this thread, I get rid of jcenter from my Jetpack Compose project by:
Modify the dependencies.kt in BuildSrc to add
object Collections {
private const val version = "0.3.4"
const val immutable = "org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:$version"
}
Modify the build.gradle(Module:) to add
implementation Libs.Collections.immutable
Replace jcenter with mavenCentral from
build.gradle(Porject:)
build.gradle(Module:)
build.gradle.kts
As a workaround, you could add explicitly to force the dependency resolution.
implementation "org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:0.3.4"
Go to this link for more info https://github.com/Kotlin/kotlinx.collections.immutable/issues/96#issuecomment-812994820
I had a spell error and caused the wrong like this, check if you had a spell error.
For my case ,I spelled 'org.jetbrains.kotlinx:kotlinx-coroutines-android' to 'org.jetbrains.kotlinx:kotlinx-coroutinesandroid' and caused the build error

how to get Dagger2 Compiler Options working?

I'm trying to use 3 of the dagger2 compiler options in my android project.
but it seems none of them actually work.
I have pasted the code from here to my gradle.properties and even compiler options of AS settings.
the 3 that I'm interested in are:
-Adagger.fastInit=enabled
-Adagger.formatGeneratedSource=disabled
-Adagger.gradle.incremental
the fastinit and codeformatting just don't work (judging by the code that is generated) but the incremental cause a compile error saying:
no compiler option found.
the versions that I'm using are:
dagger : 2.18
gradle : 5.2.1
kotlin : 1.3.21
androidPlugin : 3.3.1
For projects with multiple modules, the top build.gradle can be updated with this
allprojects {
repositories {
...
}
afterEvaluate {
extensions.findByName('kapt')?.arguments {
arg( "dagger.formatGeneratedSource", "disabled" )
}
}
}
Perhaps you should try without "A"
dagger.fastInit=enabled
dagger.formatGeneratedSource=disabled
dagger.gradle.incremental=enabled
Also can try directly in build.gradle, but this should be done for each project.
kapt {
arguments {
arg('dagger.fastInit', 'enabled')
arg('dagger.formatGeneratedSource', 'disabled')
arg('dagger.gradle.incremental', 'enabled')
}
}

Room annotation processor with Data binding

I have used Data binding in my existing code and now I am migrating to Room for persistence.
I have followed the steps mentioned in Florina's Blog for room
My Code builds fine without java code error or BR related error when I remove room dependency
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
and its runs too, but gives Runtime exception saying database_Impl does not exists. As it couldn't generate that's file.
But after I put Annotation processor back, it give me
Error:(29, 37) error: cannot find symbol class BR
My gradle plugin used is com.android.tools.build:gradle:3.0.1
They both don't seem to work together
Steps taken so far:
Changed BaseObservable to Observable As suggested here
Updated Android Studio to 3.0.1
Tried using gradle latest plugin canary 6
Clear, Clear Cache also done
Has anyone used Room and Data binding together ?
After 4 days of efforts I finally made my code run properly.
Steps to solve the
Data binding error like
error: package com.packagename.databinding does not exist
error: cannot find symbol class CustomMainActivityBinding
The app gradle must have below code added in order to view more than 100 errors that come by default
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "4000"
options.compilerArgs << "-Xmaxwarns" << "4000"
}
}
}
Gradle dependencies for data binding and Room arch components
annotationProcessor 'com.android.databinding:compiler:3.0.1'
implementation 'android.arch.lifecycle:extensions:1.0.0'
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
Note: Gradle plugin version is 3.0.1
I changed my all VMs to implement Observable and call
registry.notifyChange(this, BR.bar);
in case of notify change and also implement overridden methods
#Override
public void addOnPropertyChangedCallback(OnPropertyChangedCallback
callback) {
registry.add(callback);
}
#Override
public void removeOnPropertyChangedCallback(
OnPropertyChangedCallback callback) {
registry.remove(callback);
}
These things made my code Build, but it run without exceptions when I solved the Room query related errors. Which was the main reason, code was building but not running. These errors I could see when I Rebuid my project again.
UPDATE:
After Android studio 3.1.3, Message window is gone and now all build error appears under Build view. Although there is toggle available to get textview response of error, for data-binding errors it isn't sufficient.
Solution that helped me:
In Command promt/Terminal navigate to project root.
Run this command "./gradlew build --stacktrace" if Mac or ".\gradlew
build --stacktrace" if Windows.
Now search for "error:" tag and the compile time errors will show up.
I couldn't get these errors in IDE.
In my experience, the following reasons may cause the error:
Incorrect getter/setter (missing or incorrect name)
Incorrect return type in Dao
annotationProcessor or kapt issues
The default constructor is overridden (you need to keep the empty constructor for Room)
I faced this issue while adding room dependencies. Add this in the below way to resolve the error.
def roomVersion = "2.0.0-rc01"
implementation "android.arch.persistence.room:runtime:$roomVersion"
annotationProcessor "android.arch.persistence.room:runtime:$roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$roomVersion"

Gradle dependencies with SonarQube

I have a multi module project with Android Studio and I want to get it work with Sonarqube 5.1.
When I run:
gradlew sonarqube
I'm getting "class not found" errors, related to dependency jars. For example:
....
12:56:50.308 ERROR - Class not found: com.google.protobuf.ProtocolMessageEnum
12:56:50.309 ERROR - Class not found: com.google.protobuf.Internal
....
How can I add gradle dependencies without adding the absolute path for each dependency? Isn't it automatic?
This is my configuration
dependencies {
compile 'com.google.protobuf:protobuf-java:2.5.0'
}
sonarqube {
properties {
property 'sonar.projectName', 'myApp'
property 'sonar.java.binaries', file('build/intermediates/classes/debug')
property 'sonar.java.libraries','C:/Programs/Android/sdk/platforms/android-22/android.jar'
}
}
And this works:
property 'sonar.java.libraries','C:/Programs/Android/sdk/platforms/android-22/android.jar, PATH/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-java/2.5.0/a10732c76bfacdbd633a7eb0f7968b1059a65dfa/*.jar
If absolute paths are working for you may try to build the string like this:
def sonarLibraries = buildscript.configurations.classpath.join(",")
property 'sonar.libraries', sonarLibraries

Android: package com.google.api.services.gmail does not exist

As by documentation: https://github.com/google/google-api-java-client
To use Gradle, add the following lines to your build.gradle file:
repositories {
mavenCentral() }
dependencies {
compile 'com.google.api-client:google-api-client:1.18.0-rc' }
Done, but I get:
Error: package com.google.api.services.gmail does not exist
What could be the reason ?
You are adding Google API and trying to use Gmail API. That is why getting Error: package com.google.api.services.gmail does not exist.If you want to use Gmail API add Gmail API Client Library by adding compile 'com.google.apis:google-api-services-gmail:v1-rev29-1.20.0'
Ref: https://developers.google.com/api-client-library/java/apis/gmail/v1
com.google.api-client:google-api-client:1.20.0
on Android Studio->Project Structure->Dependencies-> "+"
you can navigate on repository declared in the gradle and choose the current version available

Categories

Resources