Manifest attributes not allowed when adding app as external librairy (android) - android

I'm currently new on Android. I try to create an app using another app project as an external library. For the moment, the two projects (two apps just created via Android Studio) are in the same folder like :
Project1
|--build.gradle
|--settings.gradle
Project2
|--build.gradle
|--settings.gradle
To add project2 as an external library, I just added to Project1/settings.gradle :
include ':MyDependency'
project(':MyDependency').projectDir = new File('D:/Projects/Project1', '../Project2')
and in the build.gradle of the application : compile project(':MyDependency').
Then, Project2 appears on the project window, so I guess it found the project.
When I then try to sync with gradle, I obtain the message
"Error:Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve project :MyDependency." and the same message for each other task in compileClassPath.
When I click on show details, the following message is displayed :
"Unable to find a matching configuration of project :MyDependency: None of the consumable configurations have attributes."
I tried each solution given for each problem, (buildTypes, clear caches, etc), but it does not work.
I also remarked that when I open Project2/app/src/main/AndroidManifest.xml, most attributes are not allowed here. Weird thing because if I open Project2 in another window on Android Studio, I don't get this message (and it builds perfectly). Once again, i tried each solution given on internet, which did not resolve my problem. I think that it's the cause of the problem.
Does anyone have an idea ?
I'm using Android Studio 3.0.1 and gradle 4.1.
Thank you very much!
Regards :)

You can change your Project2 to another module in Project1 as android library. In your project build.gradle you put include ':app', ':library-module' and in your app dependencies:
dependencies {
compile project(":library-module")
}
More info: https://developer.android.com/studio/projects/android-library.html

Dude you need to create a framwork that ‘ll share the code between your 2 apps

Related

Being to foolish to correctly implement a module library into my project

I recently started developing my really first Android Project using Android Studio 3.1.2.
Therefore I implemented a module library into my app, by cloning it from github, imported it as module library and added a dependency via right-click on app > module settings, switch to dependency tab, hit the +, select imported_module.
Additionally I checked my build.gradle(Module:app), if the dependency has been added correctly, there this line appeared:
dependencies {
...
implementation project(':imported_module')
}
Also in the settings.gradle file it says:
include ':app', ':imported_module'
Now if I want to access features of imported_module any of them can't be resolved. I browsed the official and the common forums for hours to find the one step I obviously missed but wasn't smart enough to find the solution.
Synching the project with gradle files didn't cause any visible effects
What do I still have to do to be able to use all the fancy stuff fro imported_module inside my app? Do I have to import it in a certain way?
Or do I have to modify my AndroidManifest of my app somehow? Thanks in forward!
EDIT: could it be that my app and imported_module obviously have different package names? The Project File Tree says com.domain.example.my_app for the app and com.domain.example.imported_module for imported_module. Do I have to squeeze the one into the other?
It could have been much easier, if you had mentioned what exactly you want to access in main app. May be access specifier of the member in your imported_module is private.
I kinda worked around the whole thing, by just adding a remote dependency in my build.gradle file of a new project, pasted my java classes and my res into this new project, synched it and now it runs. Nevertheless thanks for thy help!
That should be really all. Be sure to sync your project with Gradle files (File - Sync Project with Gradle Files).

Configuration with name 'default' not found

I would like to start a project in Android Studio, using Simple Facebook library.
I used to develop in Eclipse and things were fine, but now i had to face an issue while trying to make the libraries work with gradle.
I made a new project.
I made a module for official Facebook SDK inside "libraries" folder
I made a module for Simple Facebook library inside "libraries" folder
I got the following error:
Error:A problem occurred configuring project ':app'.
> Cannot evaluate module simplefacebook : Configuration with name 'default' not found.
I did my research and as everybody experienced this error message is not really informative, and i also tryed to solve this problem from stack overflow's other smiliar questions but just coudnt get it work.
Please help if you can.
And please mention in comment which gradle file you would like to see, because there are 5 of them.
Look in the docs from Facebook!
You don't need to place the hole project as library module anymore in android studio.
Facebook and many other API Providers provide ther Libs now over Maven and you only have to add the dependcy to the correct artifact in your apps build.gradle file.
Here example for Facebook SDK:
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
Copied from here: https://developers.facebook.com/docs/android/getting-started
I havn't searched for the other lib, but you should find it your self on developers.facebook.com.

NoClassDefFoundError: org.slf4j.LoggerFactory on an Android applicaton with Graphhopper

I am currently developing an Android application and I'd like to use Graphhoper 0.3 embedded in the application (I have no way of setting up a server).
I am working with Android 4.0, Eclipse Kepler, Maven 3.2.1, Android for Maven Eclipse 1.0.1.
I first tried to pull branch 0.3 and set the "core" folder up as an Eclipse project, then adding it in the Build Path of my android project. I also tried to use the graphhopper-0.3-android.jar directly.
Android Project Main Activity onStart():
GraphHopper hopper = new GraphHopper().forMobile();
Unfortunately, everytime I got the following error:
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
It does not pop in a regular Java project; only in Android.
I've tried to add the slf4j JAR's to the build path, with no success.
Any help would be greatly appreciated! It's my first post here, and I really don't know what I could try more. If you need any more information on my setup or anything, please ask!
Edit
Complete solution in comments of the validated answer.
Because you are trying to use Graphhopper directly, the Maven is not downloading all the dependencies of the Graphhopper. In order to fix this, you should either add the Graphhopper as Maven dependency, or try to resolve the dependencies 'by hand' - i.e. by adding missing classes to the build path and exporting them to the APK (if you are using Maven, then simply add the dependencies to the pom.xml without scope tag).

How do I import com.google.android.gms.* in Android Studio using a Gradle build?

I have followed the procedure as described here : Setup
I have clicked on the little 'Sync project with Gradle' button. Gradle and Android Studio seem to find everything but then I can't actually use the gms code. If I try to import, I will get autocomplete for com.google.android.gms but no further. I have updated all the packages with Android SDK Manager.
I'm running Android Studio 0.4.2.
My minSdk is set to 9
my build.gradle includes compile 'com.google.android.gms:play-services:4.0.30'
As far as the procedure is concerned I should be ready to code, but it just doesn't work. Any ideas?
[Edit, added info]
I can find the ComGoogleAndroiddGmsPlayServices3265.aar file in my exploded bundles directory. Inside of that file I also find the common directory and inside that I find the GooglePlayServicesUtil.class (which is what's not being found in my app)
I am lost.
[Edit 2]
The problem is not specific to Google Play Services OR Android Studio. I tried adding another library (HoloColorPicker) and had the same results. However, I was able to add the library's resources to my project! I was able to add them in my XML layouts and view them in my application. I was able to interact with them, they worked fine. The problem arose again when I tried to reference them in the code. Exactly like the case with gms, I had code completion when trying to import up to the point of the actual class, and I could not declare the class in the code.
I was able to use the library by cloning it and importing the project.
Also, this is not an Android Studio problem because the same thing happens on the command line with "./gradlew clean build"
This is a current bug in Android Studio: https://code.google.com/p/android/issues/detail?id=64508 to be fixed this week.
The workaround is to close the project, delete the .iml files and .idea project and re-import the project.
Keep Your compile 'com.google.android.gms:play-services:4.0.30' as very first line in build.gradle dependencies like
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:+'
}
`
Open File> Project Structure and do the following steps
Select your main module in which you want to add dependency and click on OK.
Now try to import.
I think the most important question is what you want to achieve. Not all code is under this package. Not even sure which one is.
As noted before, this is a bug with Android Studio. It just don't recognize the path for classes and shows you like if there is an error. If you try compiling you'll see that everything just work fine.
A googler recently said it'll be addressed in this week release, so, be patient and lets see whats coming.
The fact that AS is in Preview mode tell us this sort of things are going to happen :)
Android studio is crazy one, I think.
It's removed "Import module" function and you can do "New module" only.
If you are developed on Eclipse, you need export all your projects to Gradle before switch to Androids studio (WTF?)
I prefer "IntelliJ IDEA Community Edition", although It's similar Android studio but it's better than Android studio (at least until now). You just import your project as eclipse format, IntelliJ IDEA will detect dependences libraries automatic (May be you need import jar libraries by hand) and rebuild project. That Done.

Can not include source library in project in Intellij IDEA

I've created library project in IDEA with common helpers, which I use in my android applications.
Then I've created android application and included in it my library project like this tutorial said.
Everything seemed okay, code autocomplete worked fine, IDEA recognize that library and all classes and methods in it.
But then I compiled application and saw error "'org.my.helperlibrary' does not exist". However as I said IDEA acts like everything okay before making/launching project.
Here is similar question, but answer is trivial, of course my library has checked "Is Library Project" option but I still can not launch my application which use my library.
Updated:
I've just saw an error: "UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lorg/my/helperlibrary/Helper;" when I removed all usages of library in my android application. So it's just included in my app and not used.
It turned out that I should not add dependency manually in that window
I rather should add new module in my Project window at the left
Then I should choose iml file in the root folder of android library project I want to use
Then I pressed finish and from that point I had two modules in my project
After that when using classes I can press Alt+Enter on any class from SampleLibrary and tell IDEA to add module dependency
Then I could see that IDEA made all I need without me. I can now use SampleLibrary from SampleApplication!
Try to select library project, then click Build -> Compile <your library project name>.
Then back to you project which use this library and click Build -> Rebuild Project.
After that try to run project again.
Hope it helps.

Categories

Resources