tool-suite-X
tool-suite-X copied to clipboard
InstrumentationRegistry.getContext() is deprecated.
Description:
In the PropertiesNonPrivilegedTest.java
file in ODK-X Android Library, the InstrumentationRegistry.getContext()
method is used to get the context of the application. However, this method is deprecated.
Proposed fix:
Replace the InstrumentationRegistry.getContext()
method with the androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getTargetContext()
method.
Example:
// Old code
Context context = InstrumentationRegistry.getContext();
// New code
Context context = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getTargetContext();
Testing:
After making the change, rebuild and run the Project app. Run the PropertiesNonPrivilegedTest
test. The test should pass.
@Lamouresparus can you assign me this please?
hello ,Ms @Lamouresparus this is my first time contributing to an open source project through Outreachy.. could i please be assigned this task?
@Lamouresparus please can you assign it to me, thank you?
@permission-error you still have #430 and #431, I think you should clear those out first. Thank you
hello ,Ms @Lamouresparus this is my first time contributing to an open source project through Outreachy.. could i please be assigned this task?
@Giftemmanuel I have assigned this issue to you
@Lamouresparus could you please assist me in finding this file "PropertiesNonPrivilegedTest.java " i can't seem to find it throughout the "https://github.com/odk-x / tool-suite-X" repository.
@Giftemmanuel there is no code in the tool-suite-X repository. The issue description tells you which code repository the file is in.
@Giftemmanuel, the file you are seeking can be found in the Android Library repository at this location: PropertiesNonPrivilegedTest.java. The specific changes required can be pinpointed to these lines: Line 67, Line 90, and Line 128.
The recommended action is to replace the aforementioned code lines with the following: Context context = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getTargetContext();
. After making these changes, please re-run the build to ascertain if the tests now pass. If you encounter any issues or require further assistance, feel free to reach out on Slack, and we can collaborate to resolve them.
@Giftemmanuel I can help you with a detailed explanation of what @Lamouresparus wants you to do on this task.
First, you'll need to clone the androidlibrary project if you have not already cloned, and it should be on the same directory you have the services project. When you have successfully build the androidlibrary project, you are now ready to start the task.
To start the task, here are the steps to follow:
-
In the androidlibrary project, search for
PropertiesNonPrivilegedTest.java
. Here is a simple way to search in Android studio, if you are using a MacBook or Windows pc, double tap onshift
key on your keyboard or click on the search icon (Screenshot below),
-
After clicking on the search icon or double tap on
shift
key on your pc keyboard, you'll see the dialog below:
- On the highlighted portion pointed by the red arrow, type the class name:
PropertiesNonPrivilegedTest
You will see this (Screenshot below):
- Click on the class name, pointed by the arrow, it should open the class
PropertiesNonPrivilegedTest.java
.
Now you are ready to make the changes.
- In the
PropertiesNonPrivilegedTest.java
class, scroll down to line 67, 90 and 128, you will see this line of code:Context context = InstrumentationRegistry.getContext();
-
Replace each of those lines with this code:
Context context = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getTargetContext();
-
What you'll now have should look like the screenshot below in line 67, 90 and 128:
- Finally, you can head over to the last thing, which is to run the test. Click on the green double play button that is highlighted on the screenshot below to run the test, if all test passed, you're good to submit your PR.
I hope this helps. Good luck. please feel free to ask me any question if you are still not clear on what to do.
Hey @Lamouresparus , i want to add some little flavour on the code ...
Instead of writing the full package name on the code , why not import the package first and write the code without full package name .
I mean , lets import this package first
import androidx.test.platform.app.InstrumentationRegistry;
by replacing
import androidx.test.InstrumentationRegistry;
then we can make the change in code :
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
instead of the
Context context = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getTargetContext();
Any suggestion and recommendation on this ?
You can definitely use imports. I think it's for ease of explanation or possibly namespace collision in some files.
You can definitely use imports. I think it's for ease of explanation or possibly namespace collision in some files.
noted .....
Kemyikpe
thank you.. this was really helpful. i have completed the adjustment with no errors, how to i submit this please? do i send a pull request? @Lamouresparus
Yes please submit a PR.
can i expect to get this isuse assighned to me also ?
@NiranjanNlc I have assigned you the issue to practice. Unfortunatly only one PR is accepted... but there are many references to the deprecated function so if you find one you can do a PR on that.
Hey @wbrunette, thanks . I have created the pull request. It's taking more time than usual to perform simple tasks .I faced that when i run the tests , it always says that the Tests were cancelled on device . It was a lot of headache for me and happened to consumes more that usual time on this issues . However, the continuous research and testing the various ideas and steps discussed described on the internet,I found that the issuse was the replica of Google Issue Tracker. As suggested , the downgrading the ANdroid Girraffe to the older version of Android studio worked for me . By downgrading to the Android Studio Flamingo, the issue has vanished like magic. I had communicated this finding ( downgrading the android studio version) in the slack channel and many of my friends really find this useful. please review my pull request @wbrunette and suggest me if more improvement can be done . Thanks.
hello @wbrunette , I am an Outreachy applicant, and I would like to work on this issue as part of my contribution. Could you please assign it to me? thank you.