I've an Android app using retrofit 2 and okhttp for its json requests. everything was going fine until android studio(AS) oferred me the update from 3.9.6 to 4.1
The update is done easily inside the AS and it also updates the gradle plugin.
Once the update was finished I rebuild and compiled a new aab, then i notice the new file generated was 100kb smaller than the previous one (altough no code or assets changes were made, only the IDE version updated)... then i release on google play and download it in my test device (real phone). It didn't work. The app opens but it is not able to perform any okhttp request
I tried to run inside AS emulator -> it worked fine.
I tried to run in the emulator with minifyEnabled true shrinkResources true -> it worked fine
so i added to the code several debug calls in order to let me know exaclty until what line the app was working.... and i got.
try {
okHttpClient.newCall(new Request.Builder().get().url("https://www.google.com").build()).execute();
return true;
} catch (Exception e) {
return false;
}
this is a little snippet i use to test if user has internet connection.
No exception is thrown, no value is returned, the call simple dive into the okhttp api and never come back...
So i want to let clear: no code was changed, no api was updated, no r8 rules was changed
the only thing changed was the AS updated from 3.9.6 to 4.1 and some mandatory gradle plugin updated as well
after that the signed aab built got 100kb smaller and this very weird behavior started happening...
I've already tried EVERYTHING i can, but still no idea how to solve. does anyone ever face a similar problem or have idea what to do?
there are my imports
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation('com.facebook.android:facebook-login:5.13.0') {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
//retrofit
implementation('com.squareup.retrofit2:retrofit:2.9.0') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
implementation "com.squareup.okhttp3:okhttp:4.10.0-RC1"
implementation 'com.squareup.okio:okio:2.9.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation('com.squareup.retrofit2:converter-gson:2.9.0') {
exclude group: "com.google.code.gson", module: "gson"
}
I've already tried EVERYTHING i can, but still no idea how to solve. does anyone ever face a similar problem or have idea what to do?
Yes, everyone faces these problems. It's part of the learning process of being a developer. Stop focusing on this particular problem with this library for a minute and ask why you are stuck and how to get unstuck. If you reported this to a library maintainer this is what they would need to do, which is why they would ask for a clean reproduction.
Firstly read http://sscce.org/ and understand what it means and why the above question isn't getting answers. It's not a clean reproduction, it's a few random lines of code.
Then ask a a colleague to help you use a debugger, where is it stuck, what are the threads doing or waiting on.
Use the features of the library e.g. add an OkHttp Event Listener https://square.github.io/okhttp/events/.
Going back the SSCCE example, make a small example project reproducing the issue and post it to a temporary github project, then report that as a bug to OkHttp project. They can just check out the project and run it to reproduce then.
For me, I was trying to fetch data using a retrofit. Getting 400 on release build. My model was like the following:
data class ContentIdAddRQ(
#SerializedName("contentId")
val contentId: String? = null,
#SerializedName("contentType")
val contentType: String? = "VOD",
)
Then I tried adding #Keep annotation to my Model file as shown below:
#Keep
data class ContentIdAddRQ(
#SerializedName("contentId")
val contentId: String? = null,
#SerializedName("contentType")
val contentType: String? = "VOD",
)
Related
I am trying to debug an existing Android app that uses tensorflow-lite to detect objects. The app implements the tensorflow library like below :
implementation('org.tensorflow:tensorflow-lite:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-support:0.0.0-nightly') { changing = true }
But examples I have found online for object detection, have implemented tensorflow-lite in the following way :
implementation 'org.tensorflow:tensorflow-lite-task-vision:0.2.0'
My questions are:
What is the difference between using the nightly snapshot and the "normal" library. From what I can gather online, the nightly build is an experimental branch and may contain bugs? I'm just confused about this because the existing app does not contain a reference to sonatype maven repository, which I understand was required to get the nightly builds to work in the app.
allprojects {
mavenCentral
maven {
name 'ossrh-snapshot'
url 'http://oss.sonatype.org/content/repositories/snapshots'
}
}
My second question is what does this do line do : { changing = true } ?
PS: We are using our own custom trained model/tflite.
Changing, or snapshot versions are used when you need Gradle to get a new version of the dependency with the same name from time to time (once in 24 hours, unless specified explicitly otherwise).
I believe that whoever chose the nightly version of tensorflow, was wrong. As you say, this version may have bugs, and worse, these bugs will change overnight. Find some fixed version that you are comfortable with, study its changelog, and reset your implementation to refer to this version.
I would like to find out the root cause of the exception thrown, in other words, which stream and why is closed.
I'm developing an Android app and I'm using the CV_ATTACHMENT_SRV OData service. The problem is that I cannot upload media to this service.
I created a ByteStream by using the method,
ByteStream content = ByteStream.fromInput(inputStream);
I tried to use the
createMedia(EntityValue entity, StreamBase content, HttpHeaders headers)
method of the service to upload an image where the entity is basically an instance of 'OriginalContent', the content is the ByteStream created earlier, and the headers contain some additional information related OriginalContent.
This is what I get:
com.sap.cloud.mobile.odata.DataStreamException: stream is closed
at com.sap.cloud.mobile.odata.http.OKByteStreamBody.writeTo(OKByteStreamBody.java:46)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:59)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
...
I tried to figure out if I have access to the file I want to upload so I tried the above mentioned method with having a file on the external storage and packed in the apk. None of them worked.
Did you guys meet this kind of situation? I'm having a hard time finding similar situations. Please help.
For those who are interested the solution lies within upgrading the dependencies from
implementation group: 'com.sap.cloud.android', name: 'fiori', version: 3.0.0
implementation group: 'com.sap.cloud.android', name: 'onboarding', version: 3.0.0
implementation group: 'com.sap.cloud.android', name: 'odata', version: 3.0.0
implementation group: 'com.sap.cloud.android', name: 'foundation', version: 3.0.0
to 3.0.5 (most likely if you update the odata lib, it will be fine).
I get Cannot resolve symbol FirebaseVisionTextDetector error when I put in my module:
import com.google.firebase.ml.vision.text.FirebaseVisionTextDetector;
I can't understand why because in gradle I have the correct implementation:
implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
SOLVED
I have solved by downgrading to 16.0.0. Still don't know the reason why.
implementation 'com.google.firebase:firebase-ml-vision:16.0.0'
Downgrade is not really a solution. There are many bug fixes and upgrades which you should ship with your app.
FirebaseVisionTextDetector class was removed in
firebase-ml-vision:17.0.0 , it was last available in firebase-ml-vision:16.0.0 they have changed it to FirebaseVisionTextRecognizer.
There are not much difference between both classes. So go ahead and do changes.
Changes to make:
Before (v-16.0.0):
FirebaseVisionTextDetector
FirebaseVisionTextDetector.detectInImage(image)
List<FirebaseVisionText.Block> resultsBlocks = results.getBlocks();
for (FirebaseVisionText.Block block : resultsBlocks) {
for (FirebaseVisionText.Line line : block.getLines()) {
//...
}
}
After (v-18.0.1):
FirebaseVisionTextRecognizer
FirebaseVisionTextDetector.processImage(image)
List<FirebaseVisionText.TextBlock> blocks = results.getTextBlocks();
for (FirebaseVisionText.TextBlock block : blocks) {
// ...
}
}
You can clone Official ML kit sample project to see complete code implementation.
Please check link for list of class and interface which ML kit provide in vision.text package. so I guess you need to take help from FirebaseVisionTextRecognizer class.
Here is the example how you can use 'FirebaseVisionTextRecognizer' class.
I'm doing a small Android Application, currently the apk has 382KB, and I'm using OkHttp, looking inside the apk, the Okhttp inserts a file publicsuffixes.gz that has 33Kb (8~9% of total apk size).
If I exclude the file with the follow code the application crashes, so it obviously necessary, my question is, what is the function of that file and is it possible to replace or modify to reduce the size?
The exclude code:
android {
...
packagingOptions {
exclude "publicsuffixes.gz"
}
}
Firstly, this shouldn't fail if you don't configure your client to support cookies. Can you provide a stacktrace of it failing?
If you need cookies but don't care about security (YOLO!) I suspect you could hack something up by modifying https://github.com/square/okhttp/blob/9bfe575960af8e7bb164642f2f513b5ccb39ff4f/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixListGenerator.java
To have a basically empty file. It seems like a bad idea, but caveat emptor. You will break security around Cookie handling, which may or may not be acceptable to you.
in case if someone is facing HTTP FAILED: java.lang.IllegalStateException: Unable to load publicsuffixes.gz resource from the classpath issue , below given solution will work for them.
Add the following two lines to proguard-rules.pro
-keep class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
https://programmersought.com/article/25321169177/;jsessionid=A144F66609278A032E652302EB65AA95
I have use Firebase Cloud Messaging(FCM) API for the push notification in Android. When I implemented that time perfect work but now it's can not find the Service of google play.
the error is:
FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE,
Please help me how to resolve. I Have use below dependency in gradle file.
dependencies {
compile files('libs/ksoap2-android-assembly-3.4.0-jar.jar')
compile 'com.android.support:appcompat-v7:23.0.0'
compile files('libs/gson-2.2.4.jar')
compile files('libs/activation.jar')
compile files('libs/mail.jar')
compile files('libs/additionnal.jar')
compile 'com.android.support:multidex:1.0.1'
compile 'com.facebook.android:facebook-android-sdk:4.14.0'
compile 'com.google.firebase:firebase-messaging:9.0.2'
compile('com.google.android.gms:play-services:9.0.2') {
exclude group: "play-services-wallet"
exclude module: "play-services-wallet"
exclude group: "play-services-ads"
exclude module: "play-services-ads"
}
}
Thanks for taking the time to read this.
Verify internet connectivity
Verify if the Android SDK tools(Tools -> Android -> SDK manager -> SDK tools tab) has 'Google Play services' latest version and if not install the package.
Then if you are using emulator, please stop the emulator and start it again.It works
You can check
Check your internet connection with no proxy and open internet connect
Replace your google-service.json with new one you can get this in firebaseconsol
Please check your device has google play service in it and it working or not , firebase not work without google play service
Check -FireBaseInstanceId service does not get registered
After long struggle i found the answer, if google play service is not running then FirebaseInstanceId background sync failed - SERVICE_NOT_AVAILABLE log print, so you can check your google play service is running properly or not ?
May be this information is helpful to you !
the service needs to be bound in the Manifest.xml
<!-- Firebase InstanceId Service -->
<service
android:name="eu.acme.service.FireBaseInstanceIdService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
then one can access one single exposed method (the other names are obfuscated = not reliable):
package eu.acme.service;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class FireBaseInstanceIdService extends FirebaseInstanceIdService {
#Override
#android.support.annotation.WorkerThread
public void onTokenRefresh() {
/* obtain the current InstanceId token: */
String token = FirebaseInstanceId.getInstance().getToken();
}
}
one could only work around it, by not provoking it, eg. by not adding any AuthState Listener while knowing that there is no active network present, as explained here - as it seems, one otherwise cannot catch the exception thrown from within the library - which can be ignored, since it merely just complains, that there is no network connectivity.
com.google.android.gms.iid and com.google.firebase.iid are about the same.
I had to disbale my VPN - hope this helps someone !
I just had this problem. In my case, only worked when I stopped the emulator, closed it, and opened again. I didn't make any other changes.
Easiest solution is to delete the bin and obj folders under the .Droid directory.
In this way you have a clean start every time.
In my case - I rebooted my PC and it worked.
Im not an expert, so I might have covered one of the mentioned tipps by my approach
Connect your mobile with different wifi connection with different service provider. It seems weird but you can try it!
In my case, I just removed instant run from Android Studio preferences
Me too had the same issue, resolved by just Clean Project option under build. Hope it might help anyone here.
You need to update your play services and make sure your internet connectivity is good.
In my case
I have been Added google-services.json file in Project root, I moved it to app folder and problem has been fixed.
MyProjectRootDir/google-services.json
move to -->
MyProjectRootDir/app/google-services.json