This is for a simple Android app as my first step to test banner ads in an Android app.
I followed examples, guidelines, and arrived at the need for these import lines in MainActivity.java:
// these are needed for advertising:
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
But the builder cannot resolve the last two lines:
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
Why???
I use AndroidX 1.0.0 library (after migrating from Support Library 28.0.0).
The dependencies in build.gradle of the app package are:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.gms:play-services-ads:7.8.0' // added by Henrik to access AdView
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
I have of course added the layout item AdView into activity_main.xml.
I have downloaded Google Play services SDK - it did not help (no change)
I have downloaded Google Repository - it did not help (no change)
What do I miss?
The version you are using is way too old. Use the latest and compatible version. Its already there in Documentation.
implementation 'com.google.android.gms:play-services-ads:19.6.0'
Related
I am trying to integrate zoom in my application.
For that, I followed this link [https://marketplace.zoom.us/docs/sdk/native-sdks/android/getting-started/prerequisites]
I've created a new android project where I've imported the .aar files from zoom SDK as well as imported the dependencies but when I try to run this in my main application I get this error.
error: cannot find symbol
JoinMeetingOptions opts = ZoomMeetingUISettingHelper.getJoinMeetingOptions();
^
symbol: variable ZoomMeetingUISettingHelper
location: class MainActivity
Dependencies
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(path: ':commonlib')
implementation project(path: ':mobilertc')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0-rc01'
}
MainActivity
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import us.zoom.sdk.JoinMeetingOptions;
import us.zoom.sdk.JoinMeetingParams;
import us.zoom.sdk.ZoomSDK;
import us.zoom.sdk.ZoomSDKInitializeListener;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ZoomSDK sdk = ZoomSDK.getInstance();
MeetingService meetingService = sdk.getMeetingService();
sdk.initialize(this, App_Key, App_Secret, ZoomSDKInitializeListener);
JoinMeetingOptions opts = ZoomMeetingUISettingHelper.getJoinMeetingOptions();
JoinMeetingParams params = new JoinMeetingParams();
params.displayName = displayName;
params.meetingNo = meetingNo;
params.password = meetingPassword;
meetingService.joinMeetingWithParams(context, params, opts);
}
}
Suggestion 1:
Check the order of imports.
Clean gradle cache at C:\Users\<USER>\.gradle\cache
In Android Studio Invalidate & Restart
Oh yeah found the problem: (You should have just done suggestion 2)
import com.***.inmeetingfunction.customizedmeetingui.MyMeetingActivity;
import com.***.inmeetingfunction.customizedmeetingui.SimpleZoomUIDelegate;
import com.***.inmeetingfunction.customizedmeetingui.view.MeetingWindowHelper;
import com.***.inmeetingfunction.zoommeetingui.ZoomMeetingUISettingHelper;
This class ZoomMeetingUISettingHelper is not part of the SDK. Its a custom class. That's why you cannot import it. Just copy it over from the sample.
Suggestion 2:
Same as I mentioned here: Just start with their sample application. Why you trying to re-invent the wheel importing libraries and stuff. Just use their existing sample as a starting point, and then go from there, create your new Activities, Views etc. Just don't use their Activities and Views you don't need. Once you are done with all the functionality, you can remove and do some cleaning up.
You have to import both commonlib.aar and mobilertc.aar . And inside your gradle paste this two
implementation project(":commonlib")
implementation project(":mobilertc")
I have created a basic Espresso test class that looks like the following:
#LargeTest
#RunWith(AndroidJUnit4.class)
class ConfigurationsActivityTest {
#Rule
public ActivityTestRule<ConfigurationsActivity> mConfigsTestRule =
new ActivityTestRule<>(ConfigurationsActivity.class);
#Test
public void isInView() {
onView(withId(R.id.config_recyclerview)).check(matches(isDisplayed()));
}
}
The problem is, when I try to run this test I get the following error message:
Class not found: "com.name.app.activities.ConfigurationsTest"
I have followed this answer: Android Espresso test: Class not found: ...Empty test suite and taken a look at my run configurations. It seems that my test is being run as an unit test even though it's an instrumented one.
Another problem arises when I delete the unit test configurations, that were created when I tried to run my instrumented test, and try to create an instrumented test run configuration for my test class: the wizard does not allow me to select my instrumented test class containing the test above to be the test class. The problem is visualised here.
I have also taken a look at this answer: TestCase class not found by Android Studio and confirmed that my directory structure in main/java and androidTest/java are the same.
In addition, when I follow what was done in this question: Android Espresso: "No test were found" , "Process crashed" and create a run configuration for the whole package that contains my test class and run that, I get:
java.lang.RuntimeException: Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded.
I am suspecting that it's something to do with my imports or dependencies. Here are both:
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.13'
testImplementation "org.mockito:mockito-core:3.3.1"
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
}
Any help appreciated. Thanks!
The rule should be like this
#Rule
public ActivityTestRule<ConfigurationsActivity> mConfigsTestRule =
new ActivityTestRule<>(ConfigurationsActivity.class);
The test class has to be public. That's why it wasn't working.
I'm trying to use an SDK given with the RFID scanner I recently bought.
I'm trying to run the sample code given, but it won't compile. I get the following errors on compilation:
error: package android.support.v7.widget does not exist
error: package RecyclerView does not exist
I've tried all the solutions on similar posts, and I'm pretty sure I have the support library correctly installed.
Here are all my dependencies in my build.gradle (app)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.material:material:1.1.0-alpha08'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
implementation project(':Rfid.AsciiProtocol-Library')
implementation 'com.android.support:appcompat-v7:+'
implementation 'com.android.support:recyclerview-v7:26.0.0'
}
I'm new to Android Studio, and as I said I tried pretty much all the answers for similar problems and nothing works. Any help welcome :)
Thanks a lot in advance,
Cyril
You should replace android support recyclerview with androidx
implementation 'androidx.recyclerview:recyclerview:1.0.0'
And you can delete 'com.android.support:appcompat-v7:+' dependency, because you've already import it with
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
It frustrated me for literally hours because the answer here given is missing so much.
In dependencies of gradle:
import:
implementation 'androidx.recyclerview:recyclerview:1.0.0'
click gradle sync (should be a bar on top of the page that pops up
Then in your java file where u actually use the RecyclerView class, import this:
import androidx.recyclerview.widget.RecyclerView;
and you are done
EDIT: So apprently you just need to auto-fill the object you need and android studio will auto inport for you. example:
try to type recyclerview, but press tab to auto-fill it. The object should automatically be imported for you on top of the java page. This works with all android studio objects like view and intent.
After migrating to Androidx,my project start displaying a red underline error which says could not resolve R.
i have Tried googling for some similar issue but yet the error
remain,
i have checked my manifest, my Res folder for error
i have novalidate/restart project
i have clean and rebuild project
i have sync gradle with android project
yet after i have done these, the error still remains
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
// implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.github.maxyou:CalendarPicker:v1.1.2'
// Ramotion
implementation 'com.ramotion.paperonboarding:paper-onboarding:1.1.3'
implementation 'com.ramotion.foldingcell:folding-cell:1.2.3'
implementation 'com.ramotion.garlandview:garland-view:0.3.3'
}
MyApplication.java
package xyz.esusku.nearbyworker;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}```
See https://twitter.com/tasomaniac/status/1103020923874131968 for the details.
Gradle Android Plugin 3.3+ no longer generates R source file. You either need to update to the IDE that supports the new binary format for the resources or downgrade the plug-in to an older version in your build.gradle.
Hope you have added these line in gradle.properties file: as you are trying to migrate existing project.
android.useAndroidX=true
android.enableJetifier=true
one more thing try removing the duplicate import-
import android.support.v7.app.AppCompatActivity; //remove this line
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
These 3 annotations #SmallTest, #MediumTest, and #LargeTest has been recently deprecated on Android.
But I couldn't find any documentation which explains the motivation or proposes a new annotation set.
So, is there any way right now for declaring the scope of a test?
Previously these annotations were in the android.test.suitebuilder.annotation package. As of API 24, they were moved to the android.support.test.filters package (documented here for #MediumTest. #SmallTest and #LargeTest are the same).
To use the new versions:
Be sure you're using import android.support.test.filters.<size>Test at the top of your test file.
Ensure your test runner and rules versions are using at least version 0.5 in your build.gradle file:
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
Update for androidx
dependency declared in app's build.gradle:
androidTestImplementation 'androidx.test:runner:1.2.0'
and then imports looks like:
import androidx.test.filters.SmallTest;
import androidx.test.filters.MediumTest;
import androidx.test.filters.LargeTest;
import androidx.test.filters.FlakyTest;
Original answer:
Like Chris said, they are moved in the Testing Support Library as of API 24 (apps targeting this api onwards)
In order to use the annotations for JUnit/Unit tests you have to add:
testImplementation 'com.android.support.test:runner:0.5'
in your build.gradle file
and for UI/instrumentation tests add:
androidTestImplementation 'com.android.support.test:runner:0.5'
Then in your test class add one/more of the following imports:
import android.support.test.filters.SmallTest;
import android.support.test.filters.MediumTest;
import android.support.test.filters.LargeTest;
import android.support.test.filters.FlakyTest;
Update for androidx
Step 1: In your app's build.gradle file, inside dependencies add:
testImplementation 'androidx.test:runner:1.1.1'
testImplementation 'androidx.test:rules:1.1.1'
Step 2: In your test class, add the needed imports
import androidx.test.filters.LargeTest;
import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest;
Step 1: In your app's build.gradle file, inside dependencies add:
testImplementation 'com.android.support.test:runner:1.0.2'
Please note that: You have to add this line as testImplementation, not androidTestImplementation
Step 2: In your test class, add one/more of the following imports (Based on your need)
import android.support.test.filters.SmallTest;
import android.support.test.filters.MediumTest;
import android.support.test.filters.LargeTest;