Not able to communicate between two modules in an Android project? - android

My project have two modules:
App
Facebook-lib
Here are my gradle files:
setting.gradle
include ':app', ':facebook-lib'
Module App gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile project (':facebook-lib')
}
Module Facebook-lib gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
}
Whenver I am trying to access Facebook-lib class in App module. It works but I can't do vice versa.
I get com.app.testpackage doesn't exist or cannot find symbol class.
What I am doing wrong here?

You can't achieve it.
Your Module App has a dependency with the Module Facebook library. It means that you can use the classes inside the library in your main module.
Your Facebook library doesn't have a dependency with your module. It means that you can't use the classes in main module.
Also you can't create a circular dependency.

Related

Call an Activity from a service class when they belong to diffrent modules

I have two modules app and library. I have MusicMainActivity class in app module and Notification service class in library module.Now I want to call MusicMainActivity from a service class. I tried this by using
Intent in-new Intent(this,packagename.MusicMainActivity.class);
and also
Intent in-new Intent(this,MusicMainActivity.class);
But this show an error on MusicMainactivity.
Error:(326, 48) error: cannot find symbol class MusicMainActivity
Error:Execution failed for task ':library:compileReleaseJavaWithJavac'.
Compilation failed; see the compiler error output for details.
library module gradle file
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile files('libs/aacdecoder-android-0.8.jar')
}
app moudle gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.adio"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.google.firebase:firebase-messaging:9.0.0'
}
apply plugin: 'com.google.gms.google-services'
You need to add the app module as a dependency to the library module. You can do this by manually editing the build.gradle file of the library module, adding the line
compile project(':app')
Or you can use the Module Settings dialog in Android Studio.
Alternatively, you can configure an intent filter which would allow you to start your activity without explicitly using its class name in the library module. See Intents and Intent Filters for more details. This choice is actually preferable because it is much more flexible.

Trouble adding BottomBar to Android Studio

I'm trying to add BottomBar (3rd party lib) to my android studio project as a module. I get the error Error: (4, 0) Cannot get property 'compileSdkVersion' on extra properties extension as it does not exist and it's pointing to build.gradle file. I'm not sure what's wrong. Appreciate any help.
BottomBar:
https://github.com/roughike/BottomBar/blob/master/README.md#common-problems-and-solutions
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.example.bottombar.sample"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':bottom-bar')
compile 'com.android.support:appcompat-v7:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:design:' + rootProject.ext.supportLibraryVersion
testCompile 'junit:junit:' + rootProject.ext.junitVersion
}
Forget it, I figured it out. I don't need to import it as a module, just add it as a dependency.

applying a new library dependancy in android studio project structure

I have a problem with applying a new library dependancy in Project struction.
on the lesson to learn how to use google map,
Project Structure -> Module -> app -> dependancy -> library dependancy
I faced
a NoClassDefFoundError : Could not initialize classcom.android.tools.idea.structure.gradle.MavenDependencyLookupDialog
Any suggestion or feedback will be appreciated
Thank you.
my build.gradle is like this
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "org.googlemap.googlemapdemo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'}

Android Studio telling me it cannot resolve symbols?

Android Studio was telling me it couldn't resolve some symbols in my code. After research, it was apparent that my project was API level 23, which wasnt compatible with some of the code. I decided to change it to API level 21.
Below is the previous code in my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.scriptdesigninc.test_app"
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
}
I was told that I have to change it to the following,
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.scriptdesigninc.test_app"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
After I changed it, it told me I am missing the API package and that I have to download it, which I did. Then I clicked "retry" and it said it was unable to sync gradle project.
Please help, thank you in advance.
dependencies {
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}
Add the above dependency in your build.gradle file.
This is happening because Android M does not supports the Apache HTTP API

Include apk module as dependency in android studio

I have two modules in my project:
app
app_list
Both modules have java and res. app_list has some activities that I want to launch in app.
In Eclipse, I had app_list as dependency library and I was able to launch activity of app_list. In Android Studio, when I added app_list as dependency, it says:
"Error:A problem occurred configuring project ':app'.
> Dependency NewMathBuzz:app_list:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: <home>/NewMathBuzz/app_list/build/outputs/apk/app_list-release-unsigned.apk
"
app > build.gradle is as below:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.mass.mathbuzz"
minSdkVersion 7
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':app_list')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
app_list > build.gradle is as below:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.android.support:appcompat-v7:22.0.0'
}
Could someone help me with this?
Everything was fine,
basically when I changed app_list.gradle as
apply plugin: 'com.android.application' to apply plugin: 'com.android.library' and deleted applicationId from app_list.gradle
it compiled and generated apk but I was getting runtime error that was because both app and app_list both had same resource main_activity so R.java didn't have main_activity res of app_list so it was giving illegal_parameter error . When I changed name of main_activity to some unique name it solved the issue

Categories

Resources