简体   繁体   中英

error: cannot find symbol method setHttpProxy(ProxyInfo) problem when try to make toyVpn sample project in androidStudio

i downloaded a sample project from https://developer.android.com/guide/topics/connectivity/vpn under the title ToyVpn and i imported into android studio as a project and got this error: cannot find symbol method setHttpProxy(ProxyInfo) and Cannot resolve method 'setHttpProxy(android.net.ProxyInfo)

    // Create a new interface using the builder and save the parameters.
    final ParcelFileDescriptor vpnInterface;
    for (String packageName : mPackages) {
        try {
            if (mAllow) {
                builder.addAllowedApplication(packageName);
            } else {
                builder.addDisallowedApplication(packageName);
            }
        } catch (PackageManager.NameNotFoundException e){
            Log.w(getTag(), "Package not available: " + packageName, e);
        }
    }
    builder.setSession(mServerName).setConfigureIntent(mConfigureIntent);
    if (!TextUtils.isEmpty(mProxyHostName)) {
        builder.setHttpProxy(ProxyInfo.buildDirectProxy(mProxyHostName, mProxyHostPort));
    }
    synchronized (mService) {
        vpnInterface = builder.establish();
        if (mOnEstablishListener != null) {
            mOnEstablishListener.onEstablish(vpnInterface);
        }
    }
    Log.i(getTag(), "New interface: " + vpnInterface + " (" + parameters + ")");
    return vpnInterface;
}

If you check the javadocs for the VpnService.Builder class, you will see that the setHttpProxy method is added in API level 29.

The compilation error that you are getting implies that you are compiling the ToyVPN sample against an older Android API level.

You need to get hold of the SDK for Android 10 or later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM