Google cast SDK incompatible for api>24? - java

I received feedbacks from users that the cast button wouldn't show up.
At first I thought the problem might be that my app was not properly published since I was the only one being able to see the button.
After a few tests, the cast receiver app and the cast device do not seem to be the problem.I figured it might be a compatibility issue since the button wouldn't show up for devices running api>= 26 but would on api 24.
Upgrading my implementations and my api from 24 to 27 target doesn't solve the problem.
compileSdkVersion 27
defaultConfig {
applicationId 'AppId'
minSdkVersion 16
targetSdkVersion 27
versionCode 2
versionName '1.1'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Here are my dependencies:
dependencies {
implementation 'com.github.dmytrodanylyk.shadow-layout:library:1.0.3'
implementation 'com.github.medyo:fancybuttons:1.8.4'
implementation 'com.pes.materialcolorpicker:library:1.2.0'
implementation fileTree(include: ['*.jar'], dir: 'libs')
//implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-core:15.0.0'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-cast-framework:15.0.1'
implementation 'com.android.support:mediarouter-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.sofakingforever.libraries:iconpack:0.0.7#aar'
}
Note: firebase isn't at its highest version because gms and firebase have to be a the same version.
I have exactly the same issue using the sample app "cast hello world" from the Cast documentations. It works on api 24 but not higher.
Here is my Options.java:
public class Options implements OptionsProvider {
#Override
public CastOptions getCastOptions(Context context) {
return new CastOptions.Builder()
.setReceiverApplicationId(context.getString(R.string.cast_app_id))
.build();
}
#Override
public List<SessionProvider> getAdditionalSessionProviders(Context context) {
return null;
}
}
Here is my menu inflater:
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
// Setup the menu item for connecting to cast devices
CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
return true;
}
Please help.

Related

Map Fragment do not show Map details Android

I'm trying to implement the maps fragment in my application, but when I test the apps on the simulator, the map details do not show up(unlike other devices/emulators).
I'm using the Pixel 3 API 29 emulator to test the app
(build.gradle)
plugins {
id 'com.android.application'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.G26.fitnessandnutritionbuddy"
minSdk 23
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment:2.5.2'
implementation 'androidx.navigation:navigation-ui:2.5.2'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'androidx.annotation:annotation:1.4.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.google.android.gms:play-services-location:21.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
(Here is an image of the issue)
I expected to see the details of the maps (this happens in a few devices), but in general, most devices that are used for testing the app have the same issue.

Firebase registration token is not showing in Android Studio logcat

I am using the Android studio Arctic Fox version. I need to implement an automated notification app that is going to send notifications by date. I am running my apps on an actual device with the 6.0.1 android version. I have connected fcm and set up the dependencies as well. But token is not showing on logcat. Also registered the app in firebase. Any ideas why this is happening?
build:gradle(:app)
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.f1"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
build:gradle(module)
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
manifest.xml
<service android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
MyFirebaseMessagingService
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onNewToken(#NonNull String s)
{
super.onNewToken(s);
Log.d("My token", "Refreshed Token"+s);
sendRegistrationToServer(s);
}
private void sendRegistrationToServer(String s) {
}
}
If you ran the app on the device before adding the MyFirebaseMessagingService code, it probably already generated a token then. Adding the MyFirebaseMessagingService does not generate a new token, so your onNewToken will not be called.
The two options to get the token in that case are:
Call FirebaseMessaging.getInstance().getToken() from (for example) you main activity and call the same sendRegistrationToServer there.
Delete the app and its data after you added the FirebaseMessaging.getInstance().getToken() code, and reinstall the app. Deleting the data deletes the token, so then when you run the app it will generate a new token and call your onNewToken.

VerifyError rejecting class text_plain from JavaMail API

I'm developing an application that allows the user to contact me by sending an email (the user only inputs the message, sender and receiver emails are both mine). I'm trying to implement this with gmail using the JavaMail API. However, I keep getting this error at the Transport.send(mimeMessage) line.
Here are the error messages:
Caused by: java.lang.VerifyError: Rejecting class com.sun.mail.handlers.text_plain that attempts to sub-type erroneous class com.sun.mail.handlers.handler_base (declaration of 'com.sun.mail.handlers.text_plain' appears in /data/app/~~T_TRkO9R_v9j4iEdr4K9Yg==/com.example.compusec-dPeAL8DtGJvU45dJpt8xxA==/base.apk)
Caused by: java.lang.VerifyError: Verifier rejected class com.sun.mail.handlers.handler_base: java.awt.datatransfer.DataFlavor[] com.sun.mail.handlers.handler_base.getTransferDataFlavors() failed to verify: java.awt.datatransfer.DataFlavor[] com.sun.mail.handlers.handler_base.getTransferDataFlavors(): [0x4] can't resolve returned type 'Unresolved Reference: java.awt.datatransfer.DataFlavor[]' or 'Reference: javax.activation.ActivationDataFlavor[]' (declaration of 'com.sun.mail.handlers.handler_base' appears in /data/app/~~T_TRkO9R_v9j4iEdr4K9Yg==/com.example.compusec-dPeAL8DtGJvU45dJpt8xxA==/base.apk)
Here is my code:
protected Void doInBackground(Void... voids) {
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.socketFactory.port", "465");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "465");
session = javax.mail.Session.getInstance(properties, new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("sender#gmail.com","senderpass");
}
});
session.setDebug(true);
MimeMessage mimeMessage = new MimeMessage(session);
try {
mimeMessage.setFrom(new InternetAddress("sender#gmail.com"));
mimeMessage.addRecipients(Message.RecipientType.TO, String.valueOf(new InternetAddress(email)));
mimeMessage.setSubject(subject);
mimeMessage.setText(message);
Transport.send(mimeMessage);
} catch (MessagingException e) {
e.printStackTrace();
}
return null;
}
And the gradle script:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
packagingOptions {
pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
}
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
jcenter()
maven {
url "https://maven.java.net/content/groups/public/"
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
compile 'com.sun.mail:android-mail:1.6.2'
compile 'com.sun.mail:android-activation:1.6.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Use this in build.gradle:
android {
...
packagingOptions {
exclude 'META-INF/NOTICE.md'
exclude 'META-INF/LICENSE.md'
}
}
dependencies {
implementation 'com.sun.mail:android-mail:1.6.6'
implementation 'com.sun.mail:android-activation:1.6.6'
...
}
credit to last few comments on this issue
I am having the same issue. What I can tell you is that if you target Android 10 and lower (SDK 29 or lower) it works fine. I have been using it for years. However, as soon as I target Android 11 (SDK 30) then I get this error. My guess is com.sun.mail dependencies need to be updated. I'm using the latest 1.6.5 and still doesn't work. So I suggest targeting SDK 29 for now and see if that helps.
My answer here, that is in-line with other answers (as that answer explains), does provide a solution (I'll skip to the content here, details can be read there);
The issue:
API level 30 adds a new (verifier) feature that verifies that all referenced code actually exists - or fails a build.
To resolve:
If you were providing the libraries manually via /app/libs/mail.jar, /app/libs/activation.jar, and /app/libs/additionnal.jar - you can go ahead and remove them; both google() and maven() repositories are enabled in Android projects, and the latest deps are available there. They include new META-INF files, so we'll also need to remove them from the build when we update the deps;
to your project-level gradle file (/build.gradle):
buildscript {
ext {
// ...
java_mail_version = "1.6.7"
}
// ...
}
// ...
to your app/module-level gradle file (/app/build.gradle):
//...
android {
// ...
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
excludes += '/META-INF/{NOTICE.md,LICENSE.md}' // <-- This line
}
}
}
// ...
dependencies {
// ...
// Dumb Email Sending
implementation "com.sun.mail:android-mail:$java_mail_version"
// REMOVE THESE - DEPS WILL DOWNLOAD AUTOMATICALLY
//implementation 'com.sun.mail:android-activation:1.6.7' // from 1.6.4
//implementation 'com.sun.mail:android-additionnal:1.6.7' // from 1.6.4
}
// ...
That's it, issue resolved on API Level 30 - and no more lugging the .jar files around (if you were).

Google Cloud Speech to Text Error: java.lang.NoSuchMethodError: No virtual method build()Lcom/google/protobuf/GeneratedMessageLite;

I'm using Google Cloud Speech to text. For some reason, It works only the first time. After that, this error keeps appearing. I'm stuck.
java.lang.NoSuchMethodError: No virtual method
build()Lcom/google/protobuf/GeneratedMessageLite; in class
Lcom/google/cloud/speech/v1/RecognitionConfig$Builder; or its super
classes (declaration of
'com.google.cloud.speech.v1.RecognitionConfig$Builder'
build.gradle module app
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
apply plugin: 'com.jakewharton.butterknife'
ext {
grpcVersion = '1.4.0' }
android {
compileSdkVersion 28
defaultConfig {
applicationId "app.android.com.colconvert"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
} }
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.3.0'
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
} }
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.intellij:annotations:+#jar'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
// gRPC
implementation "io.grpc:grpc-okhttp:$grpcVersion"
// implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
implementation "io.grpc:grpc-stub:$grpcVersion"
implementation 'javax.annotation:javax.annotation-api:1.2'
protobuf 'com.google.protobuf:protobuf-java:3.3.1'
implementation group: 'com.google.api.grpc', name: 'grpc-google-cloud-speech-v1', version: '0.1.13'
// OAuth2 for Google API
implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}
implementation 'com.android.support:multidex:1.0.0'
}
I think there is a problem with the version that you are using. I would recommend using the latest version like the following.
implementation group: 'com.google.api.grpc', name: 'grpc-google-cloud-speech-v1', version: '1.10.0'
Hope that helps!

Google places search box disappear in my android app, is it my code?

I have the following code in a map activity :
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
#Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
destination = place.getName().toString();
}
#Override
public void onError(Status status) {
// TODO: Handle the error.
}
});
}
This is the XML fragment:
<fragment android:id="#+id/autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"/>
Here is my app build.gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.site.test"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
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'
implementation 'com.google.android.gms:play-services-maps:16.1.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.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-storage:16.1.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'
//implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.firebase:geofire-android:2.1.1'
implementation 'com.android.support:cardview-v7:21.0.+'
implementation 'com.google.android.gms:play-services-places:16.0.0'
//below added for testing
//implementation 'com.google.android.libraries.places:1.0.0'
`enter code here`}
apply plugin: 'com.google.gms.google-services'
Once the map activity is activated, I see the fragment search box in it's correct placement. Once I click it, the search box pop-up briefly appears then disappears, effectively stopping me from entering a location.
I have enabled the Google Places API, and it is correctly placed in my android manifest file.
This is what the logcat shows :
2019-03-04 00:58:55.090 6506-6506/com.site.test E/SchedPolicy: set_timerslack_ns write failed: Operation not permitted
Seems to be an issue in Places, try this
https://stackoverflow.com/a/55073542/11551260

Categories