Home > Net >  Android Studio Internet Permission issue in release version signed build
Android Studio Internet Permission issue in release version signed build

Time:03-07

when i build a debug build internet permission is working fine and in the manifest file i already given internet permission. Unfortunately when i generate a signed in version it is not working. Application is showing crash. when i debug got retrofit is not getting response so it going to catch and showing null pointer exception.

API calling is not working.

This is my manifest file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
    android:name=".Controller"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppBaseTheme"
    android:usesCleartextTraffic="true">
   <activity
        android:name=".activites.SplashScreen"
        android:exported="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Gradle file

 plugins {
    id 'com.android.application'
 }

android {
  compileSdk 31

defaultConfig {
    applicationId "com.motors"
    minSdk 21
    targetSdk 31
    versionCode 2
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile(
                'proguard-android-optimize.txt'),
                'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
    viewBinding true
}
}

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

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'androidx.navigation:navigation-fragment:2.4.1'
implementation 'androidx.navigation:navigation-ui:2.4.1'

implementation 'com.google.android.material:material:1.5.0'
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'com.google.android.gms:play-services-location:19.0.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.preference:preference:1.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.code.gson:gson:2.8.8'

// retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'

}

CodePudding user response:

Issue is not about internet permission. It occurred because you enabled minifyEnabled true. In some cases ProGuard can’t know that a class or method is being used, such as when it’s only referenced by reflection, from XML resources or from JNI code. To prevent that code from being stripped out or renamed, you have to specify additional keep rules in the ProGuard configuration. You can fix this issues by following:

  1. Write rules in proguard-rules.pro for your all network and model classes or package: -keep class com.android.appname.** { *; }
  2. minifyEnabled false

CodePudding user response:

You're issue is not about internet permission I guess. But in proguard. That's the only difference between your Debug build and release build. You can disable proguard using this instead :

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
    }
}
  • Related