AppCompatActivity.onCreate can only be called from the same library group.

After upgrading to appcompat 25.1.0 I started getting wired errors.

In my code:

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 

I get lint error:

AppCompatActivity.onCreate can only be called from within the same library group (groupId=com.android.support)

How to prevent this behavior?

+48
android appcompat android-lint
Dec 14 '16 at 19:49
source share
3 answers

As Felipe already noted in comment , this is a mistake in the preliminary version of the tools.

You can work around this until Google releases the patch by adding the following to the build.gradle project file:

 android { lintOptions { disable 'RestrictedApi' } } 

It is worth noting that this can hide the true errors in your project, since it suppresses all errors of this type, so the best option would be to lower the version of Android Studio and the tools used in the project.

+42
Dec 20 '16 at 21:11
source share

Turning off warnings in lintOptions does not look like a good option to better turn off check at the instruction level.

Add this comment above the line of code that gives the warning:

 //noinspection RestrictedApi 
+55
Mar 29 '17 at 14:37
source share

As you can see from the previous answers, this is a mistake. I recommend that you do not turn off a specific warning about the exclusion of the entire project, but only for this method. Annotate your method as follows:

 @SuppressLint("RestrictedApi") @Override public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); //your code here } 
+37
Jul 05 '17 at 12:55
source share



All Articles