I intent to use the Fuel library inside an Android project.
I added the following to my Gradle file:
//core
implementation 'com.github.kittinunf.fuel:fuel:2.1.0'
//packages
implementation 'com.github.kittinunf.fuel:fuel-android:2.1.0'
implementation 'com.github.kittinunf.fuel:fuel-json:2.1.0'
It was succesfully resolved.
I copied the quick start code to a class, and when I try to compile, I get the following:
What else is required?
Make sure you are importing:
import com.github.kittinunf.result.Result
Otherwise it tries to use Kotlin's Result class.
Related
Just trying to implement SafetyNet Safe Browsing API in an Android app and also read the documentation on : https://developer.android.com/training/safetynet/safebrowsing.html but i am unable to reference SafetyNet class
E.g : They say on documentation :
To use the Safe Browsing API, you must initialize the API by calling
initSafeBrowsing() and waiting for it to complete. The following code
snippet provides an example:
Tasks.await(SafetyNet.getClient(this).initSafeBrowsing())
I have searched for this API lib to reference SafetyNet class object but i am unable to reference it.
I have tried to add in my build.gradle :
implementation 'com.google.apis:google-api-services-safebrowsing:v4-rev20190923-1.30.3'
and
apply plugin: 'com.google.gms.google-services'
But still unable to find that class.
Anyone know how to implement this lib helper?
Ok, such a amateur mistake :D .....
Instead of
implementation 'com.google.apis:google-api-services-safebrowsing:v4-rev20190923-1.30.3'
I should use
implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
But they didn't mention that on the official documentations :D, hope to be useful for anyone when being confuse sometimes
There is a problem with the dependency package of safetynet. You can refer to the example code of safetynet on GitHub:
https://github.com/googlesamples/android-play-safetynet/blob/master/client/java/SafetyNetSample/Application/build.gradle
dependencies {
compile "com.android.support:support-v4:$support_version"
compile "com.android.support:support-v13:$support_version"
compile "com.android.support:cardview-v7:$support_version"
compile "com.android.support:appcompat-v7:$support_version"
compile "com.google.android.gms:play-services-safetynet:$google_play_services_version"
}
Definition of google_play_services_version:
ext.google_play_services_version = '11.0.1'
I am trying to reference the Fitness.SENSOR_API as documented (https://developers.google.com/android/reference/com/google/android/gms/fitness/Fitness.html#SENSORS_API).
In java I import
import com.google.android.gms.fitness.Fitness;
and reference it like
Fitness.SENSORS_API
but this doesn't seem to work in nativescript (referencing it as com.google.android.gms.fitness.Fitness.SENSORS_API).
I've logged the value :
console.log('fitness native module:',
com.google.android.gms.fitness.Fitness); //Fitness is undefined
The same is true for other classes in the com.google.android.gms.fitness package for example com.google.android.gms.fitness.FitnessOptions as referenced here: https://developers.google.com/android/reference/com/google/android/gms/fitness/FitnessOptions.Builder
Overall, Here is what I'm trying to do:
googleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(activity)
.addApi(com.google.android.gms.fitness.Fitness.SENSORS_API)
.addApi(com.google.android.gms.fitness.Fitness.HISTORY_API)
.addApi(com.google.android.gms.fitness.Fitness.RECORDING_API)
.addScope('https://www.googleapis.com/auth/fitness.activity.read')
.addScope('https://www.googleapis.com/auth/fitness.activity.write')
.addScope('https://www.googleapis.com/auth/fitness.location.read')
.build();
I do have
dependencies {
implementation 'com.google.android.gms:play-services-fitness:16.0.1'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
}
in my App_Resources/Android/app.gradle file.
Am I missing something? Do I need to extend or implement some class? Why is Fitness undefined?
My overall goal is to follow these docs (https://developers.google.com/fit/android/get-started) and connect to google fitness API
Try a clean build to make sure the dependencies are installed properly, accessing the package might return undefined only in such cases.
tns platform clean android
I am trying to customize the firebase in-app-messaging-display's UI of "Image Only" and "Modal" mode. So I turned to the official documentation, but it is quite simple, by saying:
Creating your own display is a two step process:
1.Write your own implementation of the FirebaseInAppMessagingDisplay class.
2.Register that implemenation with the headless Firebase In-App Messaging SDK.
I wonder how can I import in-app-messaging-display's source code into my project and make it work as a library.
I have downloaded its source code from github:https://github.com/firebase/firebase-android-sdk/tree/master/firebase-inappmessaging-display, tried to import it as a module, but after I selected the Source directory, Android Studio hints that: Specify location of the Gradle
or Android Eclipse project. I also have tried to copy the source code into my project's libs directory and added this: include ':libs:firebase-inappmessaging-display' into my settings.gradle file and this: implementation project(':libs:firebase-inappmessaging-display') into my app's gradle dependency. When sync building Android Studio reports errors like this:
ERROR: Unable to resolve dependency for ':XXXXXXXX': Could not resolve project :libs:firebase-inappmessaging-display.
Any suggestion will be highly appreciated.
The information on the doc is little bit confusing. I am also stuck with the same problem for long time. Actually its very simple.
Add these dependencies in your app level gradle file.
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation ("com.google.firebase:firebase-inappmessaging:17.0.3")
Register Your DisplayMessage component on starting activity.
import com.google.firebase.inappmessaging.FirebaseInAppMessaging
import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplay
///////
override fun onStart() {
super.onStart()
Log.e("MESSAGE", "activity started")
var firebaseInAppMessagingDisplay = FirebaseInAppMessagingDisplay { inAppMessage, cb ->
// You can show the message here.
// The variable inAppMessage has all information about the campaign that we putting in console (title, content, image url.. etc)
Log.e("MESSAGE", "Display Message callback invoked")
}
FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(firebaseInAppMessagingDisplay)
}
I am encountering following error while building an apk:
error: package android.arch.core.util does not exist
My java code has a line:
import android.arch.core.util.Function;
I know this exists and its doc is here.
But how can I import it?
There was a versioning problem and my problem solved with this link:
https://issuetracker.google.com/issues/66894924#comment12
I used beta version of libs and it solved the error about android.arch.core.util.Function;
I'm not sure what you are using it for but here is a sample that compiles and runs. Add the import to the class that needs it and add the code somewhere in that same class. Android Studio would not let me import it until I had code that actually used it. It may be a bug or intentional.
Import:
import android.arch.core.util.Function;
Code:
Function function = new Function<Boolean, String>() {
#Override
public String apply(Boolean input) {
return null;
}
};
Please make sure you have added the corresponding dependency in gradle
Example
implementation "android.arch.lifecycle:extensions:1.1"
Final answer
Add the below code in app/build.gradle file under "dependencies" block
// Room components
implementation "android.arch.persistence.room:runtime:1.1.0”
annotationProcessor "android.arch.persistence.room:compiler:1.1.0"
androidTestImplementation "android.arch.persistence.room:testing:1.1.0"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:1.1.0"
annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
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"