1

I am trying to load image URL using Glide. Error.

class com.bumptech.glide.load.engine.GlideException: Failed to load resource

I searched this error in google it says https issue but previous i worked in other project which also https.it was working fine.why https is issue or this is some other issue?

This links works fine

But these are not working

image link

Image Load :

   Glide.with(context)
            .load(bannerImageModel.getOutput().get(position).getBanner_img())
            .apply(new RequestOptions().
            diskCacheStrategy(DiskCacheStrategy.ALL))
            .into(view);

link 1 : https://freshtocook.in/uploads/banner/47a16ffc2fc5935dccd37574083c6201.jpg

link 2 : https://freshtocook.in/uploads/banner/7eecf823e008a0bb93f347d994b6e534.jpg

link 3 : https://freshtocook.in/uploads/banner/62d69dfa30acabbfe60bc77c5f19cc53.jpg

Full error :

javax.net.ssl.SSLHandshakeException(java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.) call GlideException#logRootCauses(String) for more detail Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE There was 1 cause: javax.net.ssl.SSLHandshakeException(java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.) call GlideException#logRootCauses(String) for more detail Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed There was 1 cause: javax.net.ssl.SSLHandshakeException(java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.) call GlideException#logRootCauses(String) for more detail Cause (1 of 1): class javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 2020-07-14 18:25:03.367 24169-24169/com.example.freshtocook I/Glide: Root cause (1 of 1) javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:239) at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:1471) at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:1415) at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:1359) at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:221) at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:144) at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:106) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:400) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:333) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:483) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:135) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:90) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:30) at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:104) at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:164) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154) at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:65) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:309) at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446) Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:668) at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:513) at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:432) at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:360) at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94) at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:89) at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:224) at com.android.org.conscrypt.ConscryptFileDescriptorSocket.verifyCertificateChain(ConscryptFileDescriptorSocket.java:430) at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.NativeSsl.doHandshake(NativeSsl.java:387) at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:234) at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:1471)  at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:1415)  at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:1359)  at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:221)  at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:144)  at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:106)  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:400)  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:333)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:483)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:135)  at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:90)  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:30)  at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:104)  at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59)  at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)  at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:164)  at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154)  at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:65)  at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)  at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)  at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:309)  at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)  at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:919)  at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)  Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:668)  at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:513)  at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:432)  at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:360)  at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)  at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:89)  at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:224)  at com.android.org.conscrypt.ConscryptFileDescriptorSocket.verifyCertificateChain(ConscryptFileDescriptorSocket.java:430)  at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)  at com.android.org.conscrypt.NativeSsl.doHandshake(NativeSsl.java:387)  at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:234)  at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:1471)  at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:1415)  at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:1359)  at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:221)  at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:144)  at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:106)  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:400)  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:333)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:483)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:135)  at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:90)  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:30)  at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:104)  at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59)  at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)  at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:164)  at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154)  at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:65)  at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)  at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)  at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:309)  at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)  at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:919)  at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)  2020-07-14 18:25:03.457 24169-24705/com.example.freshtocook I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 2020-07-14 18:25:03.458 24169-24705/com.example.freshtocook I/System.out: (HTTPLog)-Static: isSBSettingEnabled false

Now getting this error with ION lib :

/ViewRootImpl: sendUserActionEvent() mView returned. 2020-07-14 18:46:15.892 7931-8566/com.example.freshtocook E/CONSCRYPT: ------------------Untrusted chain: ---------------------- 2020-07-14 18:46:15.892 7931-8566/com.example.freshtocook E/CONSCRYPT: == Chain0 == Version: 3 2020-07-14 18:46:15.893 7931-8566/com.example.freshtocook E/CONSCRYPT: AuthorityKeyIdentifier: 418301680148d8c5ec454ad8ae177e99bf99b05e1b8018d61e1 2020-07-14 18:46:15.893 7931-8566/com.example.freshtocook E/CONSCRYPT: SubjectKeyIdentifier: 416041493ef6a0cb4e08cbdefeb4fca54cd8872b99d23a0 2020-07-14 18:46:15.893 7931-8566/com.example.freshtocook E/CONSCRYPT: Serial Number: 74e9c119b31c8edeb61e2c05de385e5a 2020-07-14 18:46:15.894 7931-8566/com.example.freshtocook E/CONSCRYPT: SubjectDN: CN=freshtocook.in 2020-07-14 18:46:15.895 7931-8566/com.example.freshtocook E/CONSCRYPT: IssuerDN: CN=Sectigo RSA Domain Validation Secure Server CA, O=Sectigo Limited, L=Salford, ST=Greater Manchester, C=GB 2020-07-14 18:46:15.916 7931-8566/com.example.freshtocook E/CONSCRYPT: Get not before: Sun May 03 05:30:00 GMT+05:30 2020 2020-07-14 18:46:15.916 7931-8566/com.example.freshtocook E/CONSCRYPT: Get not after: Tue May 04 05:29:59 GMT+05:30 2021 2020-07-14 18:46:15.916 7931-8566/com.example.freshtocook E/CONSCRYPT: Sig ALG name: SHA256withRSA 2020-07-14 18:46:15.917 7931-8566/com.example.freshtocook E/CONSCRYPT: Signature: -6902f85f8676a61300badd35bbd41f6df636081e17059b9598ab32694434ec9a6366f7618241e05491a2b5a4a53ca3e48f2e4c51b381ace0056ec403e9062abd287972488ac6262709c60af3bb02b4aa3a2e966c84ed9590b1fc6f50e957681648e0fb250111741e5dad73651cb4d9efbe97acbf2a371b0ceceec9e402bdbedf2f5dfec54844a46c4946a9404ed6a9028ddf1aaed1d34dda3a09dc551916d228b4b98abaf4d3942637651b452ba7b5909b6140f3a69ad4752dbf2d64675898e40fbbe707d3ae7cb1aeb0b210fbe46b3fc949bef45179fe3bb3b9631e586cbc3f17d9c18e8b61a02cb7d5e0413f185b7f345c5612ea8b55f61d2f2340ee63e8be

7
  • can you please provide the url which you are trying to load? Commented Jul 14, 2020 at 12:13
  • please check now i edited Commented Jul 14, 2020 at 12:15
  • could you please also provide the full text of the error? Commented Jul 14, 2020 at 12:47
  • full error pasted Commented Jul 14, 2020 at 12:57
  • may I suggest you use ion android github.com/koush/ion this is a good choice when it comes to loading images over the internet without any hassle. An HTTP SSL certificate is the closest thing to suspect. Commented Jul 14, 2020 at 12:57

1 Answer 1

1

You need to download the certificate from the source domain. just open the SSL cert and drag and drop the image into your raw directory of your android project. rename and remove the extensions and ' . ' full stops.

my dependencies look like this

dependencies {
    implementation fileTree( dir: 'libs', include: ['*.jar'] )

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    // https://mvnrepository.com/artifact/com.koushikdutta.ion/ion
    implementation group: 'com.koushikdutta.ion', name: 'ion', version: '2.2.0'



}

I'm using Ion 2.2.0 and works well with your not working images.

import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;


public class MainActivity extends AppCompatActivity {

private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    img = findViewById(R.id.ntImg);


    try {


        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        // cert file stored in \app\src\main\res\raw
        InputStream caInput = getResources().openRawResource(R.raw.freshtocook);

        Certificate ca = cf.generateCertificate(caInput);
        caInput.close();

        KeyStore keyStore = KeyStore.getInstance("BKS");
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", ca);

        String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
        tmf.init(keyStore);

        TrustManager[] wrappedTrustManagers = getWrappedTrustManagers(tmf.getTrustManagers());

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, wrappedTrustManagers, null);

        AsyncSSLSocketMiddleware sslMiddleWare = Ion.getDefault(MainActivity.this).getHttpClient().getSSLSocketMiddleware();
        sslMiddleWare.setTrustManagers(wrappedTrustManagers);
        sslMiddleWare.setHostnameVerifier(getHostnameVerifier());
        sslMiddleWare.setSSLContext(sslContext);

        Ion.with(MainActivity.this)
                .load("https://freshtocook.in/uploads/banner/47a16ffc2fc5935dccd37574083c6201.jpg")
                .asBitmap()
                .setCallback(new FutureCallback<Bitmap>() {
                    @Override
                    public void onCompleted(Exception e, Bitmap bitmap) {
                        img.setImageBitmap(bitmap);
                    }
                });

    } catch (Exception e) {

    }


}


private HostnameVerifier getHostnameVerifier() {
    return new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
            // or the following:
            // HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
            // return hv.verify("www.yourserver.com", session);
        }
    };
}

private TrustManager[] getWrappedTrustManagers(TrustManager[] trustManagers) {
    final X509TrustManager originalTrustManager = (X509TrustManager) trustManagers[0];
    return new TrustManager[]{
            new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return originalTrustManager.getAcceptedIssuers();
                }

                public void checkClientTrusted(X509Certificate[] certs, String authType) {
                    try {
                        if (certs != null && certs.length > 0) {
                            certs[0].checkValidity();
                        } else {
                            originalTrustManager.checkClientTrusted(certs, authType);
                        }
                    } catch (CertificateException e) {
                        Log.w("checkClientTrusted", e.toString());
                    }
                }

                public void checkServerTrusted(X509Certificate[] certs, String authType) {
                    try {
                        if (certs != null && certs.length > 0) {
                            certs[0].checkValidity();
                        } else {
                            originalTrustManager.checkServerTrusted(certs, authType);
                        }
                    } catch (CertificateException e) {
                        Log.w("checkServerTrusted", e.toString());
                    }
                }
            }
    };
}
}

for further support, my manifest looks like this

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:usesCleartextTraffic="true"
    android:theme="@style/AppTheme" 
    tools:ignore="GoogleAppIndexingWarning">
    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

enter image description here drag and drop the certificate from here. Click the lock icon > view the certificate > drag and drop it to your raw folder. and remember to rename and don't leave any parts other than the name.

enter image description here

Sign up to request clarification or add additional context in comments.

7 Comments

how to find latest version of ion ?
Got new error updated with question please check the top
I have tested and updated the answer. you can install the certificate as a trusted source for your app.
Working bro thank you so much such a big help....! one more doubt should call CertificateFactory everytime when i am trying to load images ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.