Can't find lib via transitive use of sub module - android

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.

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

org.apache.http.client.utils.URLEncodedUtils not correct parse text on Android 9.0

Android Studio version 3.4
app/build.gradle:
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 18
targetSdkVersion 28
versionCode 427
versionName "2.1.427"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
def AAVersion = '4.5.2'
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
annotationProcessor "org.androidannotations:ormlite:$AAVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
implementation 'com.google.android.gms:play-services-gcm:16.0.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.j256.ormlite:ormlite-android:5.1'
implementation 'commons-codec:commons-codec:1.11'
implementation 'commons-io:commons-io:2.6'
implementation 'org.apache.commons:commons-lang3:3.8.1'
implementation 'org.apache.httpcomponents:httpclient:4.3.6'
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation "org.androidannotations:ormlite-api:$AAVersion"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
private static NotificationInvoice getNotificationInvoice(NotificationFO notification) {
String notificationText = notification.getNotificationText();
String payload = "";
NotificationType type = null;
Log.d(TAG, "check_notificationText:\n" + notificationText);
List<NameValuePair> params = URLEncodedUtils.parse(new URI(notificationText), "UTF-8");
Log.d(TAG, "check_params(" + params.size() + "):\n" + params);
}
In Android 6.0 the "notificationText" success parse to List<NameValuePair>:
check_notificationText:
http://11.1.1:54401/notify?receiver=testok&system=factura_mobile&device_type=android&type=invoice&payload=11111;0000000;5.55;2019-05-16;2019-05-16;ecb6f683-63b3-4efd-b8c3-0877f1aeae8d
check_params(5):
receiver=testok, system=factura_mobile, device_type=android, type=invoice, payload=11111;0000000;5.55;2019-05-16;2019-05-16;ecb6f683-63b3-4efd-b8c3-0877f1aeae8d
As you can see the param "payload" = 11111;0000000;5.55;2019-05-16;2019-05-16;ecb6f683-63b3-4efd-b8c3-0877f1aeae8d
Nice it's correct.
But on Android 9.0 the "notificationText" not success parse :
check_notificationText:
http://11.11.11.11:54401/notify?receiver=22222222222222&system=factura_mobile&device_type=android&type=invoice&payload=3c55ba74-a85e-401b-8c1c-40ca83947768;0000000;5.55;2019-05-16;2019-05-16;1a87fb32-4543-4111-89a4-e150a7f71168
check_params(10):
[receiver=22222222222222, system=factura_mobile, device_type=android, type=invoice, payload=3c55ba74-a85e-401b-8c1c-40ca83947768, 0000000, 5.55, 2019-05-16, 2019-05-16, 1a87fb32-4543-4111-89a4-e150a7f71168]
getNotificationInvoice_FOUND_PAYLOAD -> set_to_payload_param.getValue = 3c55ba74-a85e-401b-8c1c-40ca83947768
As you can see the param "payload" = 3c55ba74-a85e-401b-8c1c-40ca83947768 but must be
3c55ba74-a85e-401b-8c1c-40ca83947768;0000000;5.55;2019-05-16;2019-05-16;1a87fb32-4543-4111-89a4-e150a7f71168
Why URLEncodedUtils not correct parse text in Android 9.0 ?
Try to use Java in-built method java.net.URLEncoder
URLEncodedUtils is deprecated in Android API 22+
List<NameValuePair> params = URLEncoder.encode(notificationText, "UTF-8");

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'
}
}

Libraries included in custom library not usable/visible in sample project 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.

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.

Categories

Resources