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

Revert Provider use in AndroidChannelBuilder and okhttp compileOnly #9039

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 8 additions & 27 deletions android/src/main/java/io/grpc/android/AndroidChannelBuilder.java
Expand Up @@ -55,33 +55,14 @@ public final class AndroidChannelBuilder extends ForwardingChannelBuilder<Androi

private static final String LOG_TAG = "AndroidChannelBuilder";

@Nullable private static final Object OKHTTP_CHANNEL_PROVIDER = findOkHttp();
@Nullable private static final Class<?> OKHTTP_CHANNEL_BUILDER_CLASS = findOkHttp();

private static Object findOkHttp() {
Class<?> klass;
private static Class<?> findOkHttp() {
try {
klass = Class.forName("io.grpc.okhttp.OkHttpChannelProvider");
return Class.forName("io.grpc.okhttp.OkHttpChannelBuilder");
} catch (ClassNotFoundException e) {
Log.w(LOG_TAG, "Failed to find OkHttpChannelProvider", e);
return null;
}
Object provider;
try {
provider = klass.getConstructor().newInstance();
} catch (Exception e) {
Log.w(LOG_TAG, "Failed to construct OkHttpChannelProvider", e);
return null;
}
try {
if (!(Boolean) klass.getMethod("isAvailable").invoke(provider)) {
Log.w(LOG_TAG, "OkHttpChannelProvider.isAvailable() returned false");
return null;
}
} catch (Exception e) {
Log.w(LOG_TAG, "Failed to check OkHttpChannelProvider.isAvailable()", e);
return null;
}
return provider;
}

private final ManagedChannelBuilder<?> delegateBuilder;
Expand Down Expand Up @@ -132,15 +113,15 @@ public static AndroidChannelBuilder usingBuilder(ManagedChannelBuilder<?> builde
}

private AndroidChannelBuilder(String target) {
if (OKHTTP_CHANNEL_PROVIDER == null) {
throw new UnsupportedOperationException("Unable to load OkHttpChannelProvider");
if (OKHTTP_CHANNEL_BUILDER_CLASS == null) {
throw new UnsupportedOperationException("No ManagedChannelBuilder found on the classpath");
}
try {
delegateBuilder =
(ManagedChannelBuilder)
OKHTTP_CHANNEL_PROVIDER.getClass()
.getMethod("builderForTarget", String.class)
.invoke(OKHTTP_CHANNEL_PROVIDER, target);
OKHTTP_CHANNEL_BUILDER_CLASS
.getMethod("forTarget", String.class)
.invoke(null, target);
} catch (Exception e) {
throw new RuntimeException("Failed to create ManagedChannelBuilder", e);
}
Expand Down
7 changes: 3 additions & 4 deletions okhttp/build.gradle
Expand Up @@ -11,18 +11,17 @@ description = "gRPC: OkHttp"
evaluationDependsOn(project(':grpc-core').path)

dependencies {
api project(':grpc-core')
api project(':grpc-core'),
libraries.okhttp
implementation libraries.okio,
libraries.guava,
libraries.perfmark
// Make okhttp dependencies compile only
compileOnly libraries.okhttp
// Tests depend on base class defined by core module.
testImplementation project(':grpc-core').sourceSets.test.output,
project(':grpc-api').sourceSets.test.output,
project(':grpc-testing'),
project(':grpc-netty'),
libraries.okhttp
project(':grpc-netty')
signature "org.codehaus.mojo.signature:java17:1.0@signature"
signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature"
}
Expand Down