0

build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "sampleapp.com.sampleapplication"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        renderscriptTargetApi = 18
        renderscriptSupportModeEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

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

ext {
    androidSupport = '25.0.1'
    junit = '4.12'
    espresso = '2.2.2'
    mockito = '2.2.26'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile("com.android.support.test.espresso:espresso-core:$espresso", {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "com.android.support:appcompat-v7:$androidSupport"
    testCompile "junit:junit:$junit"
    compile project(path: ':samplemodule')
    testCompile "org.mockito:mockito-core:$mockito"
}

build.gradle(module)

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        renderscriptTargetApi = 18
        renderscriptSupportModeEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

ext {
    androidSupportLibrary = '25.0.1'
    espresso = '2.2.2'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "com.android.support:appcompat-v7:$androidSupportLibrary"
    testCompile 'junit:junit:4.12'
}

I get the following error:

Error:(5, 45) error: package com.example.module.activity does not exist

Referred all the following posts:

Android Studio library “error: package does not exist”

Why do packages from library module does not exist upon compilation, even when Android Studio shows no errors in code?

Package does not exist when refrencing a java module Android Studio 1.0.1

Package does not exist when using separate App as a dependency

What am I doing wrong ?

Community
  • 1
  • 1
android_eng
  • 1,370
  • 3
  • 17
  • 40
  • In your app gradle file you specified the package name as `sampleapp.com.sampleapplication`. Are you using the same package name in the activity that throws the error? Or are you using? I think it should also be `sampleapp.com.sampleapplication` – arne.z Nov 29 '16 at 18:06
  • sampleapp.com.sampleapplication is the main application package the error is throw for module package – android_eng Nov 29 '16 at 18:11

2 Answers2

1

As mentioned by Rohit, "minifyEnabled true" makes sense. It seems ProGuard removes everything from the library AAR by default. Proguard-rules configuration file should be filled in properly in order to refer the classes from the main application module. Example:

-keep public class you.library.package.name.** {
    public protected *;
}
Sergey Krivenkov
  • 579
  • 1
  • 6
  • 14
0

I found the issue:

 buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

when I set miniFyEnabled false my issues were fixed. It's too weird as this is specified for release build type and I am debugging the application.

android_eng
  • 1,370
  • 3
  • 17
  • 40