Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AndroidX #665

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.2.1'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
2 changes: 1 addition & 1 deletion stetho-js-rhino/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This [Stetho](https://facebook.github.io/stetho) plugin adds a JavaScript consol
### Download
Download [the latest JARs](https://github.com/facebook/stetho/releases/latest) or grab via Gradle:
```groovy
compile 'com.facebook.stetho:stetho-js-rhino:1.4.2'
implementation 'com.facebook.stetho:stetho-js-rhino:1.4.2'
```
or Maven:
```xml
Expand Down
6 changes: 3 additions & 3 deletions stetho-js-rhino/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
Expand All @@ -19,9 +19,9 @@ android {

dependencies {
implementation project(':stetho')
implementation 'com.google.code.findbugs:jsr305:2.0.1'
implementation 'com.google.code.findbugs:jsr305:2.0.3'
implementation 'org.mozilla:rhino:1.7.6'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'androidx.annotation:annotation:1.1.0'

testImplementation 'junit:junit:4.12'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

package com.facebook.stetho.rhino;

import android.support.annotation.NonNull;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import androidx.annotation.NonNull;

/**
* <p>Formatter that tries to mimic <pre>console.log()</pre>'s format as close as possible.</p>
*
Expand Down Expand Up @@ -124,7 +124,7 @@ public CharSequence subSequence(int start, int end) {
}

// Analyze the format. We don't have named captures in android yet so we will inspect
// the groups. They are each optional but we can find out which one is whic easily.
// the groups. They are each optional but we can find out which one is which easily.
// Remember that we want to parse: %[argument_index$][flags][width][.precision]conversion
//
// - `index` ends with '$'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

package com.facebook.stetho.rhino;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.facebook.stetho.inspector.console.RuntimeRepl;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ScriptableObject;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

class JsRuntimeRepl implements RuntimeRepl {

private final @NonNull ScriptableObject mJsScope;
Expand All @@ -22,7 +25,8 @@ class JsRuntimeRepl implements RuntimeRepl {
}

@Override
public @Nullable Object evaluate(@NonNull String expression) throws Throwable {
public @Nullable
Object evaluate(@NonNull String expression) throws Throwable {
Object result;
final Context jsContext = enterJsContext();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

package com.facebook.stetho.rhino;

import android.support.annotation.NonNull;
import android.util.Log;

import com.facebook.stetho.common.LogUtil;
import com.facebook.stetho.inspector.console.CLog;
import com.facebook.stetho.inspector.console.RuntimeRepl;
import com.facebook.stetho.inspector.console.RuntimeReplFactory;
import com.facebook.stetho.inspector.protocol.module.Console;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.ImporterTopLevel;
Expand All @@ -26,6 +27,8 @@
import java.util.Map;
import java.util.Set;

import androidx.annotation.NonNull;

/**
* <p>Builder used to setup the javascript runtime to be used by stetho.</p>
*
Expand Down
12 changes: 6 additions & 6 deletions stetho-okhttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
Expand All @@ -21,20 +21,20 @@ android {

dependencies {
implementation project(':stetho')
implementation 'com.google.code.findbugs:jsr305:2.0.1'
implementation 'com.google.code.findbugs:jsr305:2.0.3'
implementation 'com.squareup.okhttp:okhttp:2.7.2'

testImplementation 'junit:junit:4.12'
testImplementation('org.robolectric:robolectric:2.4') {
exclude module: 'commons-logging'
exclude module: 'httpclient'
}
testImplementation 'org.powermock:powermock-api-mockito:1.6.1'
testImplementation 'org.powermock:powermock-module-junit4:1.6.1'
testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
testImplementation 'org.powermock:powermock-module-junit4:1.6.6'

// Needed for Robolectric and PowerMock to be combined in a single test.
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.1'
testImplementation 'org.powermock:powermock-classloading-xstream:1.6.1'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.6'
testImplementation 'org.powermock:powermock-classloading-xstream:1.6.6'

testImplementation 'com.squareup.okhttp:mockwebserver:2.7.2'
}
Expand Down
12 changes: 6 additions & 6 deletions stetho-okhttp3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
Expand All @@ -21,20 +21,20 @@ android {

dependencies {
implementation project(':stetho')
implementation 'com.google.code.findbugs:jsr305:2.0.1'
implementation 'com.google.code.findbugs:jsr305:2.0.3'
implementation 'com.squareup.okhttp3:okhttp:3.4.2'

testImplementation 'junit:junit:4.12'
testImplementation('org.robolectric:robolectric:2.4') {
exclude module: 'commons-logging'
exclude module: 'httpclient'
}
testImplementation 'org.powermock:powermock-api-mockito:1.6.1'
testImplementation 'org.powermock:powermock-module-junit4:1.6.1'
testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
testImplementation 'org.powermock:powermock-module-junit4:1.6.6'

// Needed for Robolectric and PowerMock to be combined in a single test.
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.1'
testImplementation 'org.powermock:powermock-classloading-xstream:1.6.1'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.6'
testImplementation 'org.powermock:powermock-classloading-xstream:1.6.6'

testImplementation 'com.squareup.okhttp3:mockwebserver:3.4.2'
}
Expand Down
10 changes: 5 additions & 5 deletions stetho-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {

defaultConfig {
applicationId "com.facebook.stetho.sample"
minSdkVersion 11
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -43,8 +43,8 @@ dependencies {
// way to express this is:
//
// dependencies {
// debugCompile 'com.facebook.stetho:stetho:<VERSION>'
// compile 'com.facebook.stetho:stetho-urlconnection:<VERSION>'
// debugImplementation 'com.facebook.stetho:stetho:<VERSION>'
// implementation 'com.facebook.stetho:stetho-urlconnection:<VERSION>'
// }
//
// For Stetho developers, to verify locally that things are working
Expand All @@ -54,8 +54,8 @@ dependencies {
// ./gradlew installArchives
//
// Then uncomment the Maven style dependency and comment the project one:
//releaseCompile "com.facebook.stetho:stetho-urlconnection:${VERSION_NAME}"
//releaseImplementation "com.facebook.stetho:stetho-urlconnection:${VERSION_NAME}"
releaseImplementation project(':stetho-urlconnection')

implementation 'com.google.code.findbugs:jsr305:2.0.1'
implementation 'com.google.code.findbugs:jsr305:2.0.3'
}
2 changes: 1 addition & 1 deletion stetho-timber/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
minSdkVersion 11
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
Expand Down
4 changes: 2 additions & 2 deletions stetho-urlconnection/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
Expand All @@ -13,7 +13,7 @@ android {

dependencies {
implementation project(':stetho')
implementation 'com.google.code.findbugs:jsr305:2.0.1'
implementation 'com.google.code.findbugs:jsr305:2.0.3'
}

apply from: rootProject.file('release.gradle')
13 changes: 7 additions & 6 deletions stetho/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
Expand All @@ -15,18 +15,19 @@ android {

dependencies {
implementation 'commons-cli:commons-cli:1.2'
implementation 'com.google.code.findbugs:jsr305:2.0.1'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.google.code.findbugs:jsr305:2.0.3'
implementation 'androidx.annotation:annotation:1.1.0'

implementation 'com.android.support:appcompat-v7:23.0.1' // optional
implementation 'androidx.appcompat:appcompat:1.0.2' // optional

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's optional it should be compileOnly.
AppCompat is actually used nowhere in the code. Only Core and Fragment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compileOnly is probably a no go? https://issuetracker.google.com/issues/109894265

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should only be an issue if you're trying to work with Android resources from the library, which stetho doesn't, at least as far as I can see. As long as the error doesn't pop up during compilation we're golden.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the resources still contribute to the R.class file generation which "could" lead to issues for consumers maybe at build time maybe at runtime maybe in a lint run?

I agree it is probably not anything to worry about, but I am more making the argument that if we know it isn't correct it would be best to just avoid it and star the aosp issue to hopefully move it up in the priority list.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. That. Yeah, that could be an issue for some unfortunate souls.

Defensively, call it a breaking change and raise major version. If in exchange I get rid of hard dependency of AppCompat, I'd consider it an acceptable price.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be, we need AndroidX Core, which until now was pulled in automatically as a dependency of Fragment. This should work:

implementation 'androidx.core:core:1.1.0'
compileOnly 'androidx.fragment:fragment:1.1.0'

I get error: cannot find symbol everywhere

The "everywhere" part wasn't helpful at all. Knowing which imports didn't resolve (and maybe seeing that all were from androidx.core package) would be.

Stop assuming failure, this is going to work ;)

Copy link
Author

@cristan cristan Oct 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need AndroidX core? The only places with import androidx.core are AccessibilityUtil and AccessibilityNodeInfoWrapper. AccessibilityUtil is only used in AccessibilityNodeInfoWrapper is only used from ViewDescriptor where we check whether we can access androidx.core.view.accessibility.AccessibilityNodeInfoCompat.class.getClass(). So, as far as I can see, core is just as optional as the Fragment dependency. Is there anywhere else we use core that I missed?

The "everywhere" part wasn't helpful at all

Good point: it actually isn't everywhere. It's everywhere where we use any transient dependencies like core.

Adding all the transient dependencies works:

compileOnly 'androidx.core:core:1.1.0@aar'
compileOnly 'androidx.lifecycle:lifecycle-common:2.1.0'
compileOnly 'androidx.lifecycle:lifecycle-viewmodel:2.1.0@aar'
compileOnly 'androidx.savedstate:savedstate:1.0.0@aar'
compileOnly 'androidx.activity:activity:1.0.0@aar'
compileOnly 'androidx.fragment:fragment:1.1.0@aar'

-edit: core was lost because of a formatting issue, it's now back again.

Not using @aar also gets rid of the errors:
compileOnly 'androidx.fragment:fragment:1.1.0

What shall we use?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need all the dependencies of Fragment. We only need those that we need to compile, whose API we use in our code. Fragment checks out. Core, as you mentioned, too.

If the accessibility stuff is optional, compileOnly is fine (with its own ReflectionUtil check). Otherwise implementation is the way to go. So this is it?

compileOnly 'androidx.core:core:1.0.0@aar'
compileOnly 'androidx.fragment:fragment:1.0.0@aar'

Mind the 1.0.0 as we don't want to accidentally access something that's not in v1. That way the consumer is free to choose anything from [1.0.0, 2.0.0).

Plus implementation annotations, of course.

Awesome!


I'd add proguard rules to ignore missing Fragment and Core.

-dontwarn androidx.fragment.**
-dontnote androidx.fragment.**
-dontwarn androidx.core.**
-dontnote androidx.core.**

Otherwise consumers using Proguard would get fails, if they don't use Fragment or Core, about missing classes.

It would be better to name concrete classes or entry points that are referenced in code, but this should be fine.

Or the other way around, specify the accessing classes in this project, that should work. So many possibilities!


A potential issue is that the whole module is free to reference classes from Core and Fragment but it's no longer guaranteed to be in runtime classpath. These "optional" accessors should be in separate modules, which won't leak their compileOnly dependency to the main Stetho library.

That touches publishing, which may be a problem.

Copy link
Author

@cristan cristan Oct 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just using Core and Fragment as @aar dependencies doesn't work:

compileOnly 'androidx.fragment:fragment:1.0.0@aar'

You'll get the following errors:

/Users/Cristan/repos/stetho/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompatSupportLib.java:72: error: cannot access LifecycleOwner
      return fragment.getFragmentManager();
                     ^
  class file for androidx.lifecycle.LifecycleOwner not found
/Users/Cristan/repos/stetho/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompatSupportLib.java:77: error: cannot access ViewModelStoreOwner
      return fragment.getResources();

If you want AndroidX Fragment 1.0.0 as an AAR, you'll need to define the following to solve this:

compileOnly 'androidx.lifecycle:lifecycle-common:2.0.0'
compileOnly 'androidx.lifecycle:lifecycle-viewmodel:2.0.0@aar'
compileOnly 'androidx.core:core:1.0.0@aar'
compileOnly 'androidx.fragment:fragment:1.0.0@aar'

Anyway: making the optional dependencies actually optional hasn't got anything to do with AndroidX: your master branch has the same issues. I've therefore just updated the comment.

I suggest to merge this PR and create a separate issue to make the dependency actually optional (or go the non-optional route and remove the realtime checks).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just removed the last code which still didn't assume a minSdkLevel of 14. I've removed the documentation about ActivityTracker.add and remove: the AutomaticTracker now works for everyone, so I don't think we should even mention that you can fiddle with the added / removed activities. You could even argue for making add and remove private methods.

implementation 'androidx.fragment:fragment:1.0.0' // optional

testImplementation 'junit:junit:4.12'
testImplementation('org.robolectric:robolectric:2.4') {
exclude module: 'commons-logging'
exclude module: 'httpclient'
}
testImplementation 'org.powermock:powermock-api-mockito:1.6.1'
testImplementation 'org.powermock:powermock-module-junit4:1.6.1'
testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
testImplementation 'org.powermock:powermock-module-junit4:1.6.6'
}

apply from: rootProject.file('release.gradle')
Expand Down
2 changes: 1 addition & 1 deletion stetho/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POM_NAME=Stetho
POM_ARTIFACT_ID=stetho
POM_OPTIONAL_DEPS=com.android.support:appcompat-v7
POM_OPTIONAL_DEPS=androidx.appcompat:appcompat
POM_PACKAGING=aar
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

package com.facebook.stetho.common.android;

import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -21,6 +18,10 @@

import java.util.List;

import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;

/**
* This class provides utility methods for determining certain accessibility properties of
* {@link View}s and {@link AccessibilityNodeInfoCompat}s. It is porting some of the checks from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

import android.app.Dialog;
import android.content.res.Resources;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;

import javax.annotation.Nullable;

import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;

final class FragmentCompatSupportLib
extends FragmentCompat<Fragment, DialogFragment, FragmentManager, FragmentActivity> {
private static final FragmentAccessorSupportLib sFragmentAccessor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
import android.view.View;
import android.view.ViewGroup;

import com.facebook.stetho.common.ReflectionUtil;

import java.lang.reflect.Field;

import javax.annotation.Nullable;

public final class ViewGroupUtil {
private ViewGroupUtil() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import android.annotation.TargetApi;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.support.annotation.IntDef;

import androidx.annotation.IntDef;

/**
* Compatibility layer which supports opening databases with WAL and foreign key support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

package com.facebook.stetho.inspector.elements.android;

import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -19,6 +15,11 @@

import com.facebook.stetho.common.android.AccessibilityUtil;

import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat;

public final class AccessibilityNodeInfoWrapper {

public AccessibilityNodeInfoWrapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.facebook.stetho.inspector.elements.android.window;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.WindowManager;

Expand All @@ -17,6 +16,8 @@
import java.util.Collections;
import java.util.List;

import androidx.annotation.NonNull;

class WindowRootViewCompactV16Impl extends WindowRootViewCompat {
private Context mContext;

Expand Down
Loading