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).
Related
I am having com.squareup.okhttp3:okhttp-urlconnection:3.13.1 jar as dependency in gradle file of my Android project and used as below to get the URLConnection.
protected URLConnection getStandardHTTPURLConnection(URL url) throws IOException {
return new OkHttpURLConnection(url, builder.cookieJar(new JavaNetCookieJar(CookieHandler.getDefault())).build());
}
So I updated the jar to 4.9.0 and realized that OkHttpURLConnection is not available. It is leading to noClassDefinition exception in the run time. so what are the alternatives? Is it deprecated or moved under another hood?
Below are my imports.
import okhttp3.internal.huc.OkHttpURLConnection;
import okhttp3.internal.huc.OkHttpsURLConnection;
Kindly advice.
There's a compatibility implementation you can paste in that's mentioned in the OkHttp 3.14.0 release notes.
https://square.github.io/okhttp/changelog_3x/#version-3140
From https://square.github.io/okhttp/changelog_3x/ so I guess they got removed on 4.x
The Apache HTTP client and HttpURLConnection APIs are deprecated. They
continue to work as they always have, but we’re moving everything to
the new OkHttp 3 API. The okhttp-apache and okhttp-urlconnection
modules should be only be used to accelerate a transition to OkHttp’s
request/response API. These deprecated modules will be dropped in an
upcoming OkHttp 3.x release.
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",
)
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
I wonder if there is a way to get notified about updates of the Google Android libraries such as com.android.support:support-v4, com.android.support:appcompat-v7 and so on.
I am aware that I could use compile "com.android.support:support-v4:18.0.+" with the + in my gradle build. But it would be nice to get an eMail or have an RSS Feed with the new releses of all the different android libraries by google. This would help a lot to keep the dependencies up to date and publish a new version of my app to the play store.
Edit:
I found this url https://dl.google.com/android/repository/addon.xml which is used to update the local m2repo (which includes the above mentioned librarys).
A real "push" notification solution would require lots of boring details like setting up xmpp or email accounts. However, this is a very valid question and one I have recently solved not just for appcompat libraries but for all my dependencies.
gradle-versions-plugin
This excellent plugin analyzes your depdencies and checks for newer releases. Example console output:
$ gradle dependencyUpdates
...
The following dependencies are using the latest milestone version:
- com.android.support:appcompat-v7:23.1.1
- com.android.support:cardview-v7:23.1.1
- com.android.support:recyclerview-v7:23.1.1
- com.android.support:support-annotations:23.1.1
- com.android.support.test:rules:0.4.1
- com.android.support.test:runner:0.4.1
- com.github.ben-manes:gradle-versions-plugin:0.11.3
The following dependencies have later milestone versions:
- com.android.tools.build:gradle [1.5.0-beta1 -> 2.0.0-alpha1]
- com.google.android.gms:play-services-gcm [7.5.0 -> 8.3.0]
- com.squareup.retrofit:retrofit [1.9.0 -> 2.0.0-beta2]
- net.hockeyapp.android:HockeySDK [3.5.0 -> 3.7.0-beta.2]
- org.hamcrest:hamcrest-library [1.1 -> 1.4-atlassian-1]
- org.mockito:mockito-core [1.10.19 -> 2.0.31-beta]
You can just run this any time you want to check for newer versions. And since it also supports json output format, if you really wanted to script some kind of notification, you could cronjob it and parse the json output and do whatever you'd like at that point.
Your question is interesting and it made me think on how I may address myself the problem to actually find a solution. Here's my thought: I use myself ifttt and alike and the missing point is then the monitoring of the xml data. A Google search later, I've just found this blog post which is a thoroughful description of the steps needed to get notified by mail of a change in a web page. HEY, THAT'S WHAT WE NEED!!!
I've not tested since I need to wait for an actual update but here is the resulting RSS: page2RSS android addon monitoring
Update (May 9): page2rss has been shut down on May 1st, as a consequence other services must be used/tested. Wachete seems to provide similar services, but one needs an account.
I don't know if there is an RSS or something like that, but you can visit periodically this page:
http://developer.android.com/tools/support-library/index.html
Or visit the Android Developers Blog (often Ian Lake, a Google Developer Advocate, update it with pertinent posts):
http://android-developers.blogspot.com/
We know that Android M has removed support for HttpClient. Apps linking with it will have to explicitly say so: add a library dependency in your gradle file.
But does it break backward compatibility with existing applications?
Suppose I wrote an app which supports Api level 1 and higher and it's never maintained since last year. The targetSdkLevel of the app is certainly lower than 22. Will it crash on Android M? The source code could have been lost.
The answer looks to be yes.
I looked in the Android M source code through the SDK manager, and the package for the client is not in the source.
Package name for the HttpClient:
org.apache.http.client.HttpClient
Existing paths:
org.apache.http.conn
org.apache.http.params
Ways to fix this:
Add this to your build.graddle:
android {
useLibrary 'org.apache.http.legacy'
}
Use OkHttp-UrlConnection as an almost drop in replacement by adding this to your build.graddle:
compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
Example usage:
private static OkHttpClient okHttpClient = new OkHttpClient();
HttpURLConnection urlConnection = new OkUrlFactory(okHttpClient).open(url);