#hide class not found - android

The ContentResolver class has a hidden method called getSyncStatus(...).
To make it public visible I try to add a wrapper method in ContentResolverCompat from support v4 lib.
This works so far in Eclipse but when I call make it fails with the following errors:
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/SyncStatusInfo.java:91: android.content.SyncStatusInfo cannot be resolved to a type
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:19: The import android.accounts cannot be resolved
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:137: Account cannot be resolved to a type
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:138: android.content.SyncStatusInfo cannot be resolved to a type
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:146: Account cannot be resolved to a type
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:148: android.content.SyncStatusInfo cannot be resolved to a type
My thought was that #hide is a documentation thing only and I can access it from within AOSP classes. But why I can't build my changes when I want to access hidden classes / methods?
Note: I don't want to build an Android app, I want to change / build the Android source code itself.
Edit: This isn't a duplicate of #hide class not found because #hide means that it is removed from JavaDoc but it is still accessible from Android source code itself.

Related

Failed to find code-generated model provider - AWS Amplify

I'm getting the below error:
Failed to find a code-generated model provider.
AWS amplify code which throwing this error:
Amplify.addPlugin(new AWSApiPlugin());
Amplify.addPlugin(new AWSDataStorePlugin());
Amplify.configure(context);
I am following the below tutorials:
https://docs.amplify.aws/start/getting-started/generate-model/q/integration/android
https://docs.amplify.aws/cli/graphql-transformer/overview
I have tried generating models and models get generated successfully but still while running the app I am getting above exception.
When you generate models, you should expect to find various code-generated files in your application project. One of them will be app/src/main/java/com/amplifyframework/datastore/generated/model/AmplifyModelProvider.java.
When you build your app, Android Studio will compile that java file into a class file, and include it into your binary.
At runtime, on the phone, the AWSDataStorePlugin() constructor will attempt to find that same AmplifyModelProvider by means of reflection.
I would verify that:
You do actually have the code-generated AmplifyModelProvider;
It is being built successfully;
It is not being stripped out by ProGuard/R8 minification.
If you're still not able to get it working, just use the one-argument version of the AWSDataStorePlugin(...) constructor, instead. That version allows you to explicitly specify the model provider, and does not use runtime reflection.
Amplify.addPlugin(AWSDataStorePlugin(AmplifyModelProvider.getInstance()))
Your datasource needs to be updated:
Try running modelGen, then amplifyPush tasks:
Category
Resource name
Operation
Provider plugin
Api
amplifyDatasource
Update
awscloudformation

Warning: can't find referenced method 'int save(int)' in library class android.graphics.Canvas

I'm using a no-longer maintained Umano's AndroidSlidingUpPanel library in one of my applications:
dependencies {
// .. redacted
implementation 'com.sothree.slidinguppanel:library:3.4.0'
}
Everything worked fine till now. Today I've tried to change the compileSdkVersion from 27 to 28, and the release build started to fail with a Proguard error (minifyEnabled set to true):
$ ./gradlew clean assembleRelease
> Task :app:transformClassesAndResourcesWithProguardForRelease FAILED
ProGuard, version 6.0.3
Reading input...
// many lines with 'Reading program jar...', redacted
Initializing...
Warning: com.sothree.slidinguppanel.SlidingUpPanelLayout: can't find referenced method 'int save(int)' in library class android.graphics.Canvas
// redacted
Warning: there were 1 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
BUILD FAILED in 2s
I'm using AGP v3.5.0, with android.enableR8=false configuration to favor Proguard over R8.
One of the comments in this issue suggests to ignore the warning using -dontwarn com.sothree.**, which indeed causes the build to pass.
Why this warning started to appear in the first place, and are there any possible ramifications for ignoring it?
Let's analyze the warning message:
Warning: com.sothree.slidinguppanel.SlidingUpPanelLayout: can't find
referenced method 'int save(int)' in library class
android.graphics.Canvas
Library's SlidingUpPanelLayout.java source file indeed includes a android.graphics.Canvas#save(int) method invocation:
final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);
This method is deprecated since API 26, and was marked as #removed in API 28.
The #removed annotation (along with #hide annotation) is being used by doclava tool (AOSP tool which generates public framework API stub, a.k.a. android.jar) to mark public class methods as hidden.
To summarize: the android.graphics.Canvas#save(int) method was removed from the public API, but it is still part of the runtime/framework (see also this). During minification stage Proguard analyzes the bytecode and obviously fails to find the not-anymore-public-api android.graphics.Canvas#save(int) method and displays the above warning.
This method is still present in runtime, therefore Proguard warning can be ignored given two caveats:
Since this method is not part of public API anymore, a particular vendor might alter the framework classes (i.e., by renaming/removing this method) in a way which will cause runtime errors.
This method might be removed in future AOSP version, and you probably won't notice that till this method will be called on affected device.
The warning ignore rule can be narrowed to:
-dontwarn com.sothree.slidinguppanel.SlidingUpPanelLayout
In a long run, I'd suggest to consider patching this library by yourself (by changing the functionality to use the parameterless android.graphics.Canvas#save() method), or if that's not possible - migrate to another solution.

"MissingRegistered" Lint warnings when using com.google.android.material.* UI components

I'm trying to get rid of the Lint warnings in my Android project. Doing so I run into the following type of warning messages that I do not understand:
app\src\main\res\layout-land\event_settings_fragment.xml:25: Error: Class referenced in the layout file, com.google.android.material.textfield.TextInputLayout, was not found in the project or the libraries [MissingRegistered]
<com.google.android.material.textfield.TextInputLayout
^
My app seems to be running fine, so the com.google.android.material.textfield.TextInputLayout class should be available in the project?
Note that I do get this warning on all com.google.android.material.* classes.
MissingRegistered
Summary: Missing registered class
Priority: 8 / 10
Severity: Error
Category: Correctness
NOTE: This issue is disabled by default!
You can enable it by adding --enable MissingRegistered
If a class is referenced in the manifest or in a layout file, it must also
exist in the project (or in one of the libraries included by the project. This
check helps uncover typos in registration names, or attempts to rename or move
classes without updating the manifest file properly.
See: http://tools.android.com/tips/lint-checks
If you ensure that the layout file runs without problems, you can disable the check:
app/build.gradle
android{
lintOptions{
disable "MissingRegistered"
}
}
or add tools:ignore="MissingRegistered" in the layout file to suppress the check.

error: cannot find symbol method getColor(Context,int) after adding Sugar ORM to project

I would like to use SugarOrm in my app.
If I add the followings:
compile 'com.github.satyan:sugar:1.4'
to the gradle file
and
android:name="com.orm.SugarApp"
to my mainfest's application name
I get the following error on build:
Error:(75, 55) error: cannot find symbol method getColor(Context,int)
at this line:
holder.bg.setBackgroundColor(ContextCompat.getColor(ctx, R.color.primary_move));
If I checkout to a previous version without these 2 lines, my application builds and runds without error.
Any suggestions?
From the Android Documentation:
Helper for accessing features in Context introduced after API level 4
in a backwards compatible fashion.
Do you really need that backward compatibility? Try accesing getColor from the context. You can also still useContext.getColor() while you resolve the main issue however
I have updated to compile 'com.github.satyan:sugar:1.6' and error is gone.

android data binding: how to get useful error messages

In android studio 2.1, the compile time error messages from xml mistakes are entirely non-helpful:
Error:(11, 41) error: package mypackage.databinding does not exist
Error:(15, 13) error: cannot find symbol class MyActivityBinding
The real error would usually be something like "there's no such attribute android:adapter", or "variable foo doesn't contain property bar" or something like that. But instead of actually showing such errors, it shows the above unhelpful ones, which only tell you that the bindings weren't generated because of some unknown error.
The way I use in Android Studio 4.0:
Select the top level Build: failed item on the Build Output panel
On the right part click Run with --stacktrace. When build is finished select the top Build: failed item again on the left panel. You'll get a databinding error description on the right panel:
In my case it's:
[databinding] {"msg":"Cannot find a getter for \u003ccom.google.android.material.slider.Slider app:value\u003e that accepts parameter type \u0027java.lang.Float\u0027\n\nIf a binding adapter provides the getter, check that the adapter is annotated correctly and that the parameter type matches.","file":"SliderDatabinding\src\main\res\layout\activity_main.xml","pos":[{"line0":14,"col0":8,"line1":21,"col1":41}]}
Clink on Toogle View, under the 'Build' icon will give you details logs
There's no easy way for now. In general, if you face such compilation error and error messages point at missing databinding classes it is usually either bad reference from layout (i.e. you try to access members classes you assigned do not expose - usually happens when you c&p layouts).
Even worse, when you use other code generating libraries (Icepick, Butterknife, etc) then the real culprit can be often in code completely unrelated to binding. So when something like this occur in my code, I usually check Gradle Console view and read it from the end up, ignoring all error messages related to databinding like "missing class" or "package does not exists"
One way of getting the proper error is to run gradle in a terminal with '--info', like:
gradle :app:build --info
That's not exactly integrated into AS, so I can't really accept that answer.

Categories

Resources