Could not Resolve Symbol R After Migrating to Androidx - android

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;

Related

Cannot import Android package "com.google.android.gms.ads.initialization.*"

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'

Why doesn't Android recognize "BillingClient"

I am following this guide.
https://developer.android.com/google/play/billing/integrate
my build.gradle looks like this:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
implementation "com.google.android.gms:play-services-ads:19.6.0"
implementation "com.android.billingclient:billing:3.0.0"
androidTestImplementation "com.android.support.test:runner:1.0.2"
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"
}
The Java code in Android Studios 4 does not have recommended imports for BillingClient
If I try this:
import android.billingclient ...
"billingclient" shows up red / unrecognized.
If I try this:
import androidx.billingclient ...
"billingclient" shows up red / unrecognized.
If I try this:
import import com.android.billingclient ...
"android" shows up red / unrecognized.
I am trying to port a game to Android. I have been stuck on this for days. Any help is greatly appreciated!!!
Please help!! Thanks!!
Okay, I have figured it out. After literally days.
All it was is "File>Sync Project With Gradle Files"
I am not sure why I didn't need to do this for other statements I added to gradle.

Not able to integrate zoom in my application

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")

RecyclerView “cannot resolve symbol” errors, - Android Studio

I've created a dummy project to understand Card-Based Layout.
Unfortunately, I am getting cannot resolve symbol errors on RecyclerView.
I'm quite new to programming and can't understand what went wrong.
Dependencies are added to build file:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
}
While I'm trying to create a field in Activity I'm getting cannot resolve symbol errors on RecyclerView.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
when you want to use a class you should import its library.
in this case, you haven't import recyclerview library. to fix this just change your activity code to :
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView; //recyclerview library
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Try
File > Sync Project with Gradle Files
.
Now Remove and start typing the RecyclerView again, it should show up.
You did not import the RecyclerView class, so there's no way your compiler would know what you are talking about. Simply add this line to your import statements:
import android.support.v7.widget.RecyclerView;
Your code should run fine after that.
PS:
To make your programming experience easier, you can just auto-import all the classes you need. Click here to learn more.
I hope this helps.. Merry coding!

#SmallTest, #MediumTest, and #LargeTest deprecated on Android

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;

Categories

Resources