I am getting this AIDE (Android IDE) error: "Method onRewardedVideoCompleted does not override method from superclass". The weird part is there is no errors in Android Studio. I followed this guide: https://developers.google.com/admob/android/rewarded-video
I am getting this error in AIDE:
Here is the full code: https://pastebin.com/TJCPw5BH
#Override
public void onRewardedVideoCompleted() {
Toast.makeText(this, "onRewardedVideoCompleted", Toast.LENGTH_SHORT).show();
}
All help appreciated!
I also had this issue.
This is what I did to resolve it:
In RNFirebaseAdMobRewardedVideo.java:
#Override
public void onRewardedVideoCompleted() {
// Toast.makeText(this, "onRewardedVideoCompleted",
// Toast.LENGTH_SHORT).show();
sendEvent("onRewardedVideoCompleted", null);
}
And if you receive this error after adding that code: Error:Execution failed for task ':app:transformClassesWithDexForRelease', add this to your app build.gradle:
defaultConfig {
multiDexEnabled true
}
Please let me know if this works!
Related
The method getDeclaredMethods, when called on a class object, is supposed to return an array of Method objects representing the methods that are declared directly as part of that class. It's not supposed to return any inherited methods.
This works fine when I install my app directly via Android Studio, regardless of the active build variant. Switching to a release build is not sufficient to trigger the problem.
The problem arises when compiling an APK or App Bundle (.aab) and installing the app that way. (Either directly by copying the APK onto a device, or rolling out the bundle on the Google Play Store and installing the app from there.)
Here's my test scenario, in a fresh Android Studio project, using SDK 33, minSdk 21 (Android 5.0), minifyEnabled false, and the default proguardFiles statement deleted, to make sure this isn't caused by R8 / ProGuard.
The interface:
// TestInterface.java
package com.example.testapp;
public interface TestInterface {
default String methodWithDefault() {
return "default";
}
String methodWithoutDefault();
}
The implementing class:
// TestClass.java
package com.example.testapp;
public class TestClass implements TestInterface {
#Override
public String methodWithoutDefault() {
return "non-default";
}
}
The test case:
// MainActivity.java
package com.example.testapp;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TestClass test = new TestClass();
StringBuilder sb = new StringBuilder("Methods:\n");
for (Method m : TestClass.class.getDeclaredMethods()) {
sb.append('\n').append(m.toString()).append('\n');
try {
String s = (String) m.invoke(test);
sb.append("Result: ").append(s).append('\n');
} catch (InvocationTargetException e) {
sb.append("Target exception: ").append(e.getTargetException()).append('\n');
} catch (IllegalAccessException e) {
sb.append("Illegal access.\n");
}
}
System.out.println(sb);
TextView textView = findViewById(R.id.textView);
textView.setText(sb.toString());
}
}
Contents of app/build.gradle:
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.testapp'
compileSdk 33
defaultConfig {
applicationId "com.example.testapp"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility 11
targetCompatibility 11
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
Output when running directly from Android Studio:
Methods:
public java.lang.String com.example.testapp.TestClass.methodWithoutDefault()
Result: non-default
Output when building an APK and installing it on the device:
Methods:
public java.lang.String com.example.testapp.TestClass.methodWithDefault()
Result: default
public java.lang.String com.example.testapp.TestClass.methodWithoutDefault()
Result: non-default
Questions:
Why does this happen?
What's the best way to work around it?
In typical rubber-duck debugging fashion, I found out some important details and how to work around this while improving the test-case before posting it on StackOverflow...
First, let's have some properties of the methods printed as well. We can modify MainActivity as follows:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TestClass test = new TestClass();
StringBuilder sb = new StringBuilder("Methods:\n");
for (Method m : TestClass.class.getDeclaredMethods()) {
sb.append('\n').append(m.toString()).append('\n');
sb.append("Synthetic: ").append(m.isSynthetic()).append('\n');
sb.append("Bridge: ").append(m.isBridge()).append('\n');
sb.append("Default: ").append(m.isDefault()).append('\n');
try {
String s = (String) m.invoke(test);
sb.append("Result: ").append(s).append('\n');
} catch (InvocationTargetException e) {
sb.append("Target exception: ").append(e.getTargetException()).append('\n');
} catch (IllegalAccessException e) {
sb.append("Illegal access.\n");
}
}
System.out.println(sb);
TextView textView = findViewById(R.id.textView);
textView.setText(sb.toString());
}
}
This makes Android Studio complain, because isDefault() is only available starting from SDK 24, but our minSdk is 21.
Let's increase minSdk to 24 and check the output:
Methods:
public java.lang.String com.example.testapp.TestClass.methodWithoutDefault()
Synthetic: false
Bridge: false
Default: false
Result: non-default
Oh, the inherited method is gone! If you play around with minSdk, you'll realize the issue appears with any value <= 23. So, we make the first important realization:
1. The problem only arises if minSdk is less than 24.
(Note that the actual SDK version of the Android device on which you're installing the APK doesn't seem to matter; I'm testing this all on an SDK 25 / Android 7.1.1 device.)
Let's switch back to minSdk 21, and make the call to isDefault conditional on an SDK version check, like so:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TestClass test = new TestClass();
StringBuilder sb = new StringBuilder("Methods:\n");
for (Method m : TestClass.class.getDeclaredMethods()) {
sb.append('\n').append(m.toString()).append('\n');
sb.append("Synthetic: ").append(m.isSynthetic()).append('\n');
sb.append("Bridge: ").append(m.isBridge()).append('\n');
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
sb.append("Default: ").append(m.isDefault()).append('\n');
}
try {
String s = (String) m.invoke(test);
sb.append("Result: ").append(s).append('\n');
} catch (InvocationTargetException e) {
sb.append("Target exception: ").append(e.getTargetException()).append('\n');
} catch (IllegalAccessException e) {
sb.append("Illegal access.\n");
}
}
System.out.println(sb);
TextView textView = findViewById(R.id.textView);
textView.setText(sb.toString());
}
}
This yields the following output when installing the new APK on a device with SDK version 24 or newer:
Methods:
public java.lang.String com.example.testapp.TestClass.methodWithDefault()
Synthetic: true
Bridge: false
Default: false
Result: default
public java.lang.String com.example.testapp.TestClass.methodWithoutDefault()
Synthetic: false
Bridge: false
Default: false
Result: non-default
Confusingly, the method is not marked as default. But it's marked as synthetic, so:
2. We can filter out the inherited methods via Method.isSynthetic().
So, to answer our questions:
Why does this happen?
I suppose the synthetic method is being generated when minSdk is less than 24 because the APK could be installed on an older Android device which doesn't have "direct" support for default interface methods in its JVM.
When installing the app directly via Android Studio, I guess the minSdk value is ignored, since Android Studio can check what the actual version of the device is.
If anyone has more exact information, please share.
What's the best way to work around it?
The inherited default methods can be filtered out by calling isSynthetic() on them, which will return true.
If you want to keep some other synthetic methods and only filter out these ones, I don't know how to achieve that, but that should be an exceedingly rare situation.
I have implemented Billing Library from the following url
https://developer.android.com/google/play/billing/billing_library_overview#java
I am getting error on this line
if (billingResult.getResponseCode() == BillingResponse.OK) {
it says Cannot resolve symbol 'BillingResponse'
here is the complete code from above link
billingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingResponse.OK) {
// The BillingClient is ready. You can query purchases here.
}
}
#Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
});
I have added following dependency in my apps build.gradle file
dependencies {
...
implementation 'com.android.billingclient:billing:2.1.0'
}
but I am getting error
I cannot even import it manually
import com.android.billingclient.api.BillingClient.BillingResponse;
I know its simple solution is to just replace
BillingResponse.OK
with
BillingClient.BillingResponseCode.OK
but my question is why its not given in documentation then?
I checked the source codes and figured out the correct code.
Though the code on google documentation says billingResult.getResponseCode() == BillingResponse.OK it should be billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
So all you need to do is replace BillingResponse.OK with BillingClient.BillingResponseCode.OK
MainActivity cannot be converted to LifecycleOwner
I used this as LiveCycle Owner, but it is rejected and I got an error as you see in the picture.
I work on Api 25 and I this the problem may be related to this version
This is info about my sdk
compileSdkVersion 25
buildToolsVersion '25.0.2'
This is my code:
private void retrieveTasks() {
Log.d(TAG, "Actively retrieving the tasks from the DataBase");
// Extract all this logic outside the Executor and remove the Executor
// Fix compile issue by wrapping the return type with LiveData
LiveData<List<TaskEntry>> tasks = mDb.taskDao().loadAllTasks();
// Observe tasks and move the logic from runOnUiThread to onChanged
tasks.observe(this, new Observer<List<TaskEntry>>() {
#Override
public void onChanged(#Nullable List<TaskEntry> taskEntries) {
Log.d(TAG, "Receiving database update from LiveData");
mAdapter.setTasks(taskEntries);
}
});
}
I put LiveData dependencies in my Gradle
compile "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
If anyone knows the reason for the problem, let me know please
Fragments and Activities in Support Library 26.1.0 and later already implement the LifecycleOwner interface by default
but in version 25 you need to implement LifecycleOwner interface
for example
public class MyActivity extends Activity implements LifecycleOwner {
private LifecycleRegistry mLifecycleRegistry;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLifecycleRegistry = new LifecycleRegistry(this);
mLifecycleRegistry.markState(Lifecycle.State.CREATED);
}
#Override
public void onStart() {
super.onStart();
mLifecycleRegistry.markState(Lifecycle.State.STARTED);
}
#NonNull
#Override
public Lifecycle getLifecycle() {
return mLifecycleRegistry;
}
}
Source : Handling lifecycles with lifecycle-aware components
As you can read here the LifecycleOwner was added in support library 26.1.0. Easiest way to fix your issue would be upgrading your support library version.
Had the same error. Upgrading to androidx support libraries fixed the issue.
Choose inside Android Studio: Refactor -> Migrate to android x
EDIT :
*The entire issue was that since i miss-read .makeText for .makeToast, since
i have corrected this i have found that both of the previous attempts actually work for my app. *
I'm having issues implementing Toast.makeToast method in my android app :
I tried
public void onRightCardExit(Object dataObject) {
Toast.makeToast(MainActivity.this, "Right", Toast.LENGTH_SHORT).show();
}
as well as
public void onLeftCardExit(Object dataObject) {
Toast.makeToast(getApplicationContext(), "Left", Toast.LENGTH_SHORT).show();
}
On the first one i get the issue
"Can not resolve method 'makeToast.(android.Content.Context,
java.lang.String, int)' "
On the second one a similiar but just more specific pointer to my java file for the context
"Can not resolve method
'makeToast.(com.sanruza.alpak.tinderlike.MainActivity,
java.lang.String, int)' "
I understand that the correct syntax is .makeToast( context, String, int ), but i still can't get it to work.
It should be makeText instead of makeToast
Toast.makeText(context,toastMsg, Toast.LENGTH_SHORT).show();
See the docs for more info..
Please read the Google Developers link: Developers Toast Document
This snapshot should clarify your concern:
makeToast does not exist, you must use makeText.
Toast.makeText(getApplicationContext(), "Msg", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Msg", Toast.LENGTH_LONG).show();
I am trying to integrate facebook to my Android application. When i added internet permission in the project and have generated App_ID but when I put facebook files in to my project it gives these errors as shown in pic.
Now should I remove #Override or am I missing something.
If I put this code into my OnCreate method it also gives errors to remove #Override.
facebook.authorize(this, new DialogListener() {
#Override
public void onComplete(Bundle values) {}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
Should I include facebook.apk if yes then Where to add this? please help
I followed many tutorials but could not resolve these errors.
This is most likely because you are switching between Java 1.5 and Java 1.6. In 1.5 you couldn't mark interface implementations with #Override, but you can in 1.6.
#Override annotation error (android prefs)
Bug with Override annotations in Eclipse