Libraries included in custom library not usable/visible in sample project Android - android

i'm creating simple library which make call to weather api, in my lib-project i use RxJava and RxAndroid and retrofit for http calls.
My WeatherService make the call and receive result as json and need to make some manipulations and return it as Single<CurrentWeather> to the client app.
In my lib-project i add to gradle all needed dependencies for rx and retrofit.
My library gradle:
ext{
rxJava = "2.1.17"
rxAndroid = "2.0.2"
support = "27.1.1"
retrofitVersion = "2.4.0"
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$support"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
implementation "io.reactivex.rxjava2:rxandroid:$rxAndroid"
implementation "io.reactivex.rxjava2:rxjava:$rxJava"
}
Now in my sample app in MainActivity i wanted to test one function to see if it works as expected, but when i try call the function which return Single it show comlpile error:
error: cannot access Single
class file for io.reactivex.Single not found
lib function declaration:
public Single<Current> getCurrentWeather(double lat, double lng) {
return mClient.getWeather(lat + "," + lng).flatMap(new Function<JSONObject, SingleSource<Current>>() {
#Override
public SingleSource<Current> apply(JSONObject jsonObject) throws Exception {
//parse jsonObject and return as Single<Current>
return Single.create(new SingleOnSubscribe<Current>() {
#Override
public void subscribe(SingleEmitter<Current> emitter) throws Exception {
Current current = new Current();
emitter.onSuccess(current);
}
});
}
});
}
Client app MainActivity: Here i have the compile error.
WeatherService.getIsnstance().getCurrentWeather(32.5554, 35.545)
Client app gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(":weatherlib")
}
Client app settings.gradle:
include ':app', ':weatherlib'
Do i miss something here ?
Do this means that everyone who will wish to use this lib will have to add rx dependencies in their gradle too?

You need to use api instead of implementation for your library's dependencies.
See here for the difference between them.

Related

Required Transition found: MaterialContainerTransform?

In my activity, I'm trying to use MaterialContainerTransform but it shows an error that
Required Transition found: MaterialContainerTransform
override fun onCreate(savedInstanceState: Bundle?) {
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback())
//this is giving error
window.sharedElementEnterTransition = MaterialContainerTransform().apply {
addTarget(android.R.id.content)
duration = 300L
}
window.sharedElementReturnTransition = MaterialContainerTransform().apply {
addTarget(android.R.id.content)
duration = 250L
}
My dependencies
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//material
implementation 'com.google.android.material:material:1.3.0-alpha02'
def coroutines_version = "1.3.8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
}
There are two types of MaterialContainerTransform the com.google.android.material.transition.MaterialContainerTransform that uses AndroidX Transition and includes bug fixes that apply to all API levels and the com.google.android.material.transition.platform.MaterialContainerTransform class that is built on the framework Transition class.
Only the framework Transition version can be used for window transitions, so you should make sure you're importing the right version of MaterialContainerTransform:
import com.google.android.material.transition.platform.MaterialContainerTransform

Can't find lib via transitive use of sub module

Android Studio 3.4.2
I has main project (app) that use module mytransport like this:
app/build.gradle
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation('com.crashlytics.sdk.android:crashlytics:2.7.0#aar') { transitive = true; }
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation project(':mytransport')
}
In mytransport/build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
}
In mytransport code I success use code like this:
in MyProject\mytransport\src\main\java\com\mycompany\android\mytransport\util\MyUtil.java
snippet:
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
public class JSONUtil {
private static GsonBuilder gsonbuilder = new GsonBuilder();
Nice.
Now I want in main app to use gson lib.
So in main app I try this in
MyProject\android\MyProject\app\src\main\java\com\mycompany\android\myproject\main\MainApp.java
snippet
import android.app.Application;
import android.content.Context;
public class MainApp extends Application {
private static GsonBuilder gsonbuilder = new GsonBuilder();
but I get compile error:
Cannot resolve symbol 'GsonBuilder'
Why it can't find gson lib in main app? I use it TRANSITIVE by mytransport module
Use api instead of implementation.
In mytransport/build.gradle:
dependencies {
//...
api 'com.google.code.gson:gson:2.8.5'
}
Just an example.
In library/build.gradle:
dependencies {
api project(':libraryA')
}
In app/build.gradle:
dependencies {
api project(':library')
}
In your app you will be able to access both library and libraryA.
Using the implementation configuration:
In library/build.gradle:
dependencies {
implementation project(':libraryA')
}
In app/build.gradle:
dependencies {
implementation project(':library')
}
In this case in your app you can't access the libraryA methods.

Retrofit class file for retrofit2.Retrofit not found

I have the following dependencies in my application:
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'org.slf4j:slf4j-api:1.7.21'
implementation 'net.danlew:android.joda:2.7.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.7.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
I initially had different versions of the retrofit libraries which were causing errors. Refrofit dependency issues I have resolved that issue. However, now on the compilation, I get the following error:
error: cannot access Retrofit
class file for retrofit2.Retrofit not found
The method that results in this error is the getClient method.
As far as I know, this is the right way to initialise
private static Retrofit retrofit = null;
private static int REQUEST_TIMEOUT = 60;
private static OkHttpClient okHttpClient;
public static Retrofit getClient(Context context)
{
if (okHttpClient == null)
initOkHttp(context);
if (retrofit == null)
{
retrofit = new Retrofit.Builder()
.baseUrl(CaselotREST.CASELOT_BASEURL)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
Probably a problem in gradle.build. A possible variant of why this is happening to you is to use an instance of Retrofit in another module. You need to add dependencies for Retrofit to your application module or wherever you need dependencies.
I had same problem.
for me dependencies block was out of android block in build.gradle for app.
solution: move dependencies block into android{ } block.
android{
.
.
.
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'com.squareup.retrofit2:retrofit:2.7.2'
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
implementation 'com.squareup.okhttp3:okhttp:3.6.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
}

Pinterest sdk callback class error: cannot access Response class file for com.android.volley.Response not found

I am trying to integrate Pinterest for sharing blog/creating a pin. I am following the official documentation, tutorial1 and tutorial2 to integrate the Pinterest.
But, the issue is when I try to authorize the user and pass PDKCallback object into the login method as shown below,
pdkClient.login(this, scopes, new PDKCallback() {
#Override
public void onSuccess(PDKResponse response) {
Log.d(getClass().getName(), response.getData().toString());
//user logged in, use response.getUser() to get PDKUser object
}
#Override
public void onFailure(PDKException exception) {
Log.e(getClass().getName(), exception.getDetailMessage());
}
});
It shows me the following compilation error
cannot access Response class file for com.android.volley.Response not found
Can anybody help me with this problem?
Edit
My pdk module gradle file is as follows:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation 'com.android.support:appcompat-v7:21.0.3'
implementation 'com.android.volley:volley:1.1.1'
// implementation 'com.mcxiaoke.volley:library:1.0.19'
}
My app module build.gradle file's dependency is as follows
dependencies {
implementation('com.crashlytics.sdk.android:crashlytics:2.5.2#aar')
{
transitive = true
}
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.google.code.gson:gson:2.8.4'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.firebase:firebase-client-android:2.4.0'
implementation 'com.plattysoft.leonids:LeonidsLib:1.3.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation project(':wScratchViewLibrary')
implementation project(':linkedin-sdk')
implementation project(':pdk')
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.0'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.j256.ormlite:ormlite-android:4.48'
implementation 'com.j256.ormlite:ormlite-core:4.48'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.android.gms:play-services-auth:16.0.0'
implementation 'com.google.android.gms:play-services-plus:15.0.1'
implementation 'com.facebook.android:facebook-share:4.33.0'
implementation ('com.twitter.sdk.android:twitter:3.3.0#aar') {
transitive = true
}
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
implementation "com.mixpanel.android:mixpanel-android:5.4.1"
implementation "com.google.android.gms:play-services-gcm:15.0.1"
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.wang.avi:library:2.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.6.0'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
implementation files('libs/nineoldandroids-library-2.4.0.jar')
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'com.github.cooltechworks:ScratchView:v1.1'
}
My PinterestApi class from which I try to access the login method of pdk.
package com.veriloginqr.android.sharing_apis;
import android.content.Context;
import android.util.Log;
import com.pinterest.android.pdk.PDKCallback;
import com.pinterest.android.pdk.PDKClient;
import com.pinterest.android.pdk.PDKException;
import com.pinterest.android.pdk.PDKResponse;
import java.util.ArrayList;
import java.util.List;
public class PinterestApi {
private static final String appID = "my_app_id_i_wont_reveal";
private PDKClient pdkClient;
private Context context;
public PinterestApi(Context context) {
this.context=context;
// Call configureInstance() method with context and App Id
pdkClient = PDKClient.configureInstance(context, appID);
// Call onConnect() method to make link between App id and Pinterest SDK
pdkClient.onConnect(context);
PDKClient.setDebugMode(true);
}
public void authorizeUser(){
List<String> scopes = new ArrayList<>();
scopes.add(PDKClient.PDKCLIENT_PERMISSION_READ_PUBLIC);
scopes.add(PDKClient.PDKCLIENT_PERMISSION_WRITE_PUBLIC);
pdkClient.login(context,scopes,new PDKCallback(){
#Override
public void onSuccess(PDKResponse response) {
Log.d(getClass().getName(), response.getData().toString());
//user logged in, use response.getUser() to get PDKUser object
}
#Override
public void onFailure(PDKException exception) {
Log.e(getClass().getName(), exception.getDetailMessage());
}
});
}
}
Note: You can check the pdk source code here.
try changing the volley version from 1.0.0 to 1.0.1 like this
implementation 'com.android.volley:volley:1.1.1'
or I think you should be adding volley in your app’s build.gradle
Imports & codes seems fine. The issue seems to be not downloading the whole dependency nor, there was a problem when building which needs a rebuild-clean project.
The solution will be using the latest version:
implementation 'com.android.volley:volley:1.1.1'
And making sure offline work not checked in the Settings.

GeoFire SetLocation Not Working

I am trying to save a location to geofire but not getting any response from console and in logs.
I have added the dependency in gradle files and created my database reference like this:
DatabaseReference pickupRef = FirebaseDatabase.getInstance().getReference(AppConstants.PICK_UP_REF);
pickupRef.keepSynced(true);
and the string AppConstants.PICK_UP_REF equals PickUpRef. In my activity, I have done this:
Log.d(TAG, "UID in PUR:\t" + uid);
GeoFire mGeoFire = new GeoFire(pickupRef.child(uid));
if (mLastLocation != null) {
mGeoFire.setLocation(uid, new GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()), new GeoFire.CompletionListener() {
#Override
public void onComplete(String key, DatabaseError error) {
if (error != null){
Log.d(TAG, "Write complete");
} else {
Log.d(TAG, "Write Failed:\t" + error.getMessage());
}
}
});
The oncompletionlistener never gets fired and nothing is updated in my database. Anyone else faced this problem or have I misconfigured it?
Here's my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.jjoey.transportr"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.reginald:editspinner:1.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
implementation 'com.google.firebase:firebase-storage:12.0.1'
implementation 'com.firebase:geofire-android:2.3.1'
implementation 'com.google.android.gms:play-services-nearby:12.0.1'
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services-places:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:27.1.1'
}
apply plugin: 'com.google.gms.google-services'
Change your dependencies like below in app grandle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.reginald:editspinner:1.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebase:geofire-android:2.3.1'
implementation 'com.google.android.gms:play-services-nearby:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:27.1.1'
}
And change in Project grandle:
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.1'

Categories

Resources