How does Android Studio gradle plugin manage resource files (AndroidManifest.xml)? - android

I have my project's build.gradle located in myApp/app/ directory. AndroidManifest.xml is in myApp/app/src/main directory, at the same level as java/ and res/ directories.
When synchronizing the project, I receive notification about missing manifest file. No wonder, actually, when the path is really incorrect. Source file is set as:
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
and the error notification says:
Error:Cause: java.io.FileNotFoundException: /home/aqv/AndroidStudioProjects/myApp/src/main/AndroidManifest.xml (No such file or directory)
When I change the source to:
sourceSets {
main {
manifest.srcFile 'main/AndroidManifest.xml'
}
}
the text changes to:
Error:Cause: java.io.FileNotFoundException: /home/aqv/AndroidStudioProjects/myApp/app/main/AndroidManifest.xml (No such file or directory)
As you can see, there is missing path fragment: myApp/app/src/ (when setting src/main/AndroidManifest.xml path, the error says about looking for manifest file in myApp/src/main, so it ommits the app/ directory).
Is it a kind of gradle's bug or my project is misconfigured?
Looking for solution I found one thread at SO, but the solution from there didn't work in my case. I have dependencies set as:
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:appcompat-v7:19.1.0'

Writing an answer since could be also issue for someone.
By default Android Studio creates multi module project. So you have build.gradle in the root folder of your project and another build.gradle in app folder:
<your project name>
/app
/src
build.gradle
build.gradle
settings.gradle
The parent build.gradle is usually edited if you want to specify default settings for all subprojects. It looks odd since you have only one subproject for now.
The topic starter issue was that he was adding/modifying root build.gradle instead of app folder build.gradle.

Related

Using FCM in Cordova

I am using FCM in a Cordova project. I created a project in FCM web console and generated the google-services.json file with my project's package name com.mycompany.myapp. I had to put this file in two places to succeed compilation: the android project root folder and the 'CordovaLib' sub-folder. The problem is that each of these two copies should specify a different package name: the copy of the project root folder should specify com.mycompany.myapp and the copy in CordovaLib should specify com.apache.cordova. Otherwise, the project will not compile.
When I modify the package name in the file google-services.json manually, the compilation succeeds, but no notification are delivered.
My question is: how can I generate a google-services.json file that works with Cordova? What package name should I specify in FCM console (com.mycompany.myapp or com.mycompany.myapp)? Can I generate a file that works for many packages?
[EDIT]
If you need to know, the Cordova project is generated from a Sencha ExtJS6 application, and I use "cordova-plugin-fcm". In platforms\android folder, there is a folder called CordovaLib that contains build.gradle and src. The project will not compile if I don't copy google-services.json to this location. the classes in this src folder have the package name com.apache.cordova.
As the comments on the question suggested, the solution was to put google-services.json in the root of the project only. I will explain why I had this problem, so that others may not commit the same error.
When you create your project and application in Firebase Console, you get a window with the following instructions:
Add Firebase to your Android app
The Google services plugin for Gradle loads the google-services.json file you just downloaded. Modify your build.gradle files to use the plugin.
1 - Project-level build.gradle (<project\>/build.gradle):
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.0.0'
}
}
2 - App-level build.gradle (<project>/<app-module>/build.gradle):
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
So, I added the apply plugin ... line in the build.gradle file in the sub-folder CordovaLib (which is wrong, it should go in the same build.gradle file in the project root folder), and it would not compile unles I add google-services.json in that folder. So, the source of the error was following the above instructions without thinking.
Conclusion: In Android applications generated by Cordova, put both modifications in the build.gradle file at the root of the project, and put google-services.json in the root only.

Integrating Notificare Push Notification service manually in android studio project

I am writing this post in order to help other users get through the issues i faced while integrating Notificare notification service in android project in android studio. as I have to integrate Notificare, Segment.io, Branch.io, Google places Autocomplete, In app purchase and main problem faced to me is the clashing of multiple libraries and getting of duplicate entry errors. As Notificare it self has the inappbilling library code, google analytics, play services and its own notification code. I tried the traditional way of integrating the library as provided in the notificare android studio integration the compile command in gradle file way, but that didnt work as i used to get duplicate entry for the inappbilling code which was already present in the library.
So here is the procedure.
Download the sdk folder from the notificare sdk source with sample
and then rename folder from sdk to notificare and then create a gradle file in the notificare folder as it doesnt have the gradle file by following steps:
create build.gradle file manually in notificare project. and copy the following code in it:
apply plugin: 'com.android.library'
dependencies {
compile 'com.android.support:support-v4:21.0.3'
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
above code is taken from this link.
then in the libs folder the notificare-push-lib.jar file rename to extn .zip extract the zip so we can remove contents clashing with other libraries. then in the com folder delete the android folder which has vendor-billing folder which will clash with your in app purchase implementation.
once the folder is deleted select the contents of folder which will be like com, META-INF and re select all 3 folders and compress them to zip.
This step is very important for mac users:
as you create zip file the mac automatically creates __MACOSX folder which needs to be removed which can be done using following command in terminal:
zip -d notificare.zip __MACOSX/\*
this will remove the __MACOSX folder within the zip.
Now rename the zip file to jar file with following command:
mv notificare.zip notificare.jar
copy this file and replace it in your project notificare libs folder
then in your main project app/build.gradle file add following command:
compile project(":notificare")
compile 'com.google.android.gms:play-services:8.4.0'
and also add following in main project settings.gradle file :
include ':app', ':notificare'
project(':notificare').projectDir = new File('notificare')
Clean project.
Sync gradle.
build the project it should run and the notificare should register your device.

How to access .java files from a directory outside of a package in android-studio?

I try to solve this problem for hours now and didn't find a solution on the internet.
my project looks like this:
I want to access the files in the marked directory in the de.MayerhoferSimon.Vertretungsplan package. (yes, I know packages should be lowercase.)
Is this possible and when yes, how?
I tried some things with the dependencies in the .gradle file of the :app module but nothing worked.
In this case you should create a library module for your webuntisaccessor code instead of putting this in the libs folder.
root
settings.gradle
app
build.gradle
webuntisaccessor
src
main
java
build.gradle
In settings.gradle:
include ':webuntisaccessor' , ':app'
In webuntisaccessor/build.gradle
apply plugin: 'com.android.library'
In app/build.gradle add:
dependencies {
compile project(':webuntisaccessor')
}

Unable to add AndEngine to Android Studio

I am trying to almost 2 days to add AndEngine to Android Studio but unable to do so. I tried the following two methods, neither worked.
1st Try
I download the AndEngine code from GitHub Link -- this is NOT a Gradle Project
and tried to add it to my Android Studio build.gradle and settings.gradle, but i get this error, my screenshot: https://postimg.cc/image/5mcvpvsar/
(I think I am getting this error because AndEngine is not a gradle project - HOW TO MAKE IT A GRADLE PROJECT??)
2nd Try
I have also tried adding the andengine.jar (file I just googled for) in /libs folder and do right-click --> "Add as Library" but still I cannot do "import org.andengine...." in my project files.
All tutorials available online are in Eclipse, I am using Android Studio.
I am not even able to start.
UPDATE: Yes, I gave up using Android Studio for AndEngine! Took me 15mins to do this in Eclipse, compared to the unsuccessful weekend (which i will never get back!) I spent on Android Studio
I use this techique: I set this in my settings.gradle
include 'andengine'
project(':andengine').projectDir = new File(settingsDir, '../relative/path/to/andengine')
that is in the root directory of the project (I think gradle has already created it for your main project).
In AndEngine use a build.gradle like the following for the AndEngine project
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
and add in the dependencies of your project
compile project(':andengine')
Maybe you have to close and reopen Android Studio, but normally for me this works.
BTW after have write the answer I see that someone has opened a pull request for a gradle build file.
I created a tutorial for this - How to add Andengine, Andengine Tile Map, Andengine PhysicsBox2D to Android Studio 0.8.9.
Here is the link, I hope everything works - https://docs.google.com/document/d/1zk2QjNiPvkj52G4qSVivEPrLfkCUVqmnCVH8TfsnER8/edit
ANDENGINE WITH ANDROID STUDIO 0.8.9
Note: I am using the AnchorCenter brach and TortoiseGit to get all the files.
Download Andengine from github using TortoiseGit: https://github.com/nicolasgramlich/AndEngine
After the dowload use TortoiseGit to switch to branch GLES2-AnchorCenter
Create new project in Android Studio
Create new module:
Select File -> New Module -> Android Library
Set Application name to AndEngine
Set Module Name to AndEngine
Set Package Name to org.andengine
Set Minimum SDK 14
Target SDK 19
Compile with 19
Theme None
Keep clicking next until module is created (no difference what you pick)
Enter the folder where you have downloaded Andengine, enter src/org/andengine and copy all the files inside.
Paste the copied files into your new module in your project src/java/org.andengine. After pasting everything remove tha MainActivity that was created on default
Enter the folder where you have downloaded Andengine, copy AndroidManifest and paste it into your new module (src/main)
Add the module to the project:
Select File-> Project Structure -> app-> Dependencies
Click the “+” button and pick “Module Dependency”
Select from the list your AndEngine Module
Check your project gradle in app folder (build.gradle) and make sure you have a line like this under dependencies - compile project(':AndEngine')
You should now be able to use AndEngine in your project
ANDENGINE TMX TILED MAP EXTENSION WITH ANDROID STUDIO 0.8.9
Note: We do this the same way like with Andengine but we change a few things:
Download AndengineTMX from github using TortoiseGit: https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension
After the dowload use TortoiseGit to switch to branch GLES2-AnchorCenter
Create new project in Android Studio
Create new module:
Select File -> New Module -> Android Library
Set Application name to AndEngineTMXTiledMapExtension
Set Module Name to AndEngineTMXTiledMapExtension
Set Package Name to org.andengine.extension.tmx
Set Minimum SDK 14
Target SDK 19
Compile with 19
Theme None
Keep clicking next until module is created (no difference what you pick)
Enter the folder where you have downloaded AndengineTMX , enter src/org/andengine/extension/tmx and copy all the files inside.
Paste the copied files into your new module in your project src/java/org.andengine.extension.tmx. After pasting everything remove tha MainActivity that was created on default
Enter the folder where you have downloaded AndengineTMX, copy AndroidManifest and paste it into your new module (src/main)
Add the module to the project:
Select File-> Project Structure -> app-> Dependencies
Click the “+” button and pick “Module Dependency”
Select from the list your AndengineTMX Module
Check your project gradle in app folder (build.gradle) and make sure you have a line like this under dependencies - compile project(':AndEngineTMXTiledMapExtension')
You should now be able to use AndEngineTMXTiledMapExtension in your project.
ANDENGINE PHYSICSBOX2D WITH ANDROID STUDIO 0.8.9
Download this file - http://d-h.st/FyC
Unzip the file
You should have 2 jar files, copy them to your project app/libs
Right click on andenginephysicsbox2dextension.jar and select “Add as library” (or something like this)
Open your build.gradle in your app folder
Under dependencies add compile files('lib/physicsbox2d_so_files.jar')
You should now be able to use PhysicsBox2D in your project.
As the question's answers havn't been accepted yet, and I know people are still searching for solutions to this, I found this great website with very very clear and concise instructions to import AndEngine to your Android Studio projects. Here's the link:
http://geq-i.blogspot.com/2014/02/how-to-setup-andengine-in-android-studio.html
All credits go to the user who created this page. I can attest to the fact that this is working perfectly. I JUST used this website after trying 10s of different ways.
Only thing to note on the link is the last part:
$ cd <project folder>/AndEngine/src/main
$ rm -r java/org
$ mv org java
This part is copying the org folder from . to ./main/java. Best way to do this is to just drag and drop the org folder into main/java when the project has finished building once.
Hope this helps!
Well i had the same problem - This helped me to solve it.
http://www.makethegame.net/android-andengine/how-to-setup-andengine-with-android-studio/
Check out this tutorial on how to use andengine in android studio
http://javaprogrammernotes.blogspot.in/2014/05/settings-up-andengine-in-android-studio.html
Brief Summary of the Tutorial(Check out the full tutorial if you face any issue):
Let's assume that you already have created a project and it has default structure. First create folder named third_party in the root directory of the project. Then in third_party directory create subdirectories called andengine and andenginebox2d. I assume that you already downloaded or cloned AndEngine and Box2d extension for it. Put AndEngine and AndEngineBox2d in andengine and andenginebox2d directories respectively. Create file named build.gradle in andengine directory and andenginebox2d directory. Build.gradle files is a file that tells gradle how to build your project.
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-project.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Open settings.gradle that is located in your project's root directory and add two lines to it:
include ':third_party:andengine'
include ':third_party:andenginebox2d'
Next open build.gradle which locates in app directory and add
compile project(':third_party:andengine')
The final step is to open AndroidManifest.xml in andegine and andenginebox2d directories and make them look like this:
<!--?xml version="1.0" encoding="utf-8"?-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.andengine">
<application>
</application>
</manifest>
application block is needed because of bug in manifest merging tool.
That's it! Now clean your project and press run. Everything should work just fine.

Android Studio Gradle Configuration with name 'default' not found

I am having problems compiling my app with Android Studio (0.1.5).
The app uses 2 libraries which I have included as follows:
settings.gradle
include ':myapp',':library',':android-ColorPickerPreference'
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':library')
compile project(':android-ColorPickerPreference')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
When compiling I get this message:
Gradle: A problem occurred configuring project ':myapp'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
Could you help me with this message? Thanks!
In my case, after compiling with gradle tasks --info, the log was there :
Evaluating project ':libraries:VolleyLibrary' using empty build
file.
So it failed to find build.gradle file of the library.
Reason is the folder structure.
It was
-libraries
--volley
---VolleyLibrary
It is supposed to be
-libraries
--VolleyLibrary
I forgot to pull all submodules. So my
compile project(':something')
could not be resolved.
Solution
git submodule update --init
compile fileTree(dir: '//you libraries location//', include: ['android-ColorPickerPreference'])
Use above line in your app's gradle file instead of
compile project(':android-ColorPickerPreference')
Hope it helps
The following procedure solved my issue:
Go to your sub-project-module/library-module settings. (press F4 after selecting the module)
Right Click on Add > Android-Gradle.
Add build.gradle to your module.
Add the following script
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
add include ':yourModuleName' in your settings.gradle
I've also faced with this error - I forgot to create build.gradle script for library project.
Yet another cause - I was trying to include a module in settings.gradle using
include ':MyModule'
project(':MyModule').projectDir = new File(settingsDir, '../../MyModule')
Only problem was, I had just imported the module from Eclipse an forgot to move the directory outside my application project, i.e. the path '../../MyModule' didn't exist.
My solution is to simply remove a line from the settings.gradle file, which represents a module that doesn't exist:
include ':somesdk'
and also remove the corresponding line from the main project's build.gradle:
compile project(':somesdk')
I had a git submodule problem when getting this error. Try running gradle tasks --info for a more detailed problem description. I first used gradle tasks --debug, which was not nearly as helpful as --info.
Suppose you want to add a library (for example MyLib) to your project, You should follow these steps:
Prepare your library as a gradle Android library if your library's type is Eclipse ADT
For this job it's enough to import it in Android Studio
Copy your library folder, in this case MyLib folder, and paste it in your main project folder. It's a good practice to create a new folder in your main project folder and name it Libraries
Go to Android Studio and open Settings.gradle file, there you should include your library in your main project. For example include ':MyPrj', 'Libraries:MyLib'. Note: Current directory for this include statement is your main project folder. If you paste your project into a folder you must mention it's address relative to the main project directory. In my case I paste MyLib into Libraries folder. This Libraries name is not a keyword and you can choose other names for it
Open your Project Structure page(File->Project Structure...) click on modules then click on your main project go to dependencies tab click on + then choose Module dependency and there is your libraries and you can select them as you want
Hope it help
In my case I was using Gradle files that work under Windows but failed on Linux. The include ':SomeProject' and compile project(':SomeProject') were case sensitive and were not found.
For me folder was missing which was declared under settings.gradle.
Everything looks fine at first blush, but some poking around on here found an answer that could be helpful: https://stackoverflow.com/a/16905808/7944
Even the original answer writer doesn't sound super confident, but it's worth following up on. Also, you didn't say anything about your directory structure and so I'm assuming it's boring default stuff, but can't know for sure.
One other potential cause of this precise error: I found this error was resolved by commenting some unused libraries in build.gradle dependencies section. Make sure these paths and such are all correct.
I'd look real close at your compile project(':android-ColorPickerPreference') entry in the build.gradle - try commenting out the related code and this line in build.gradle and see if that compiles - then go from there resolving the path or library issue.
I had similar issue and found very simple way to add a library to the project.
Create folder "libs" in the root of your project.
Copy JAR file into that folder.
Go back to Android Studio, locate your JAR file and right click it, choose "Add As Library...", it will ask you only to which module you want to add it, well choose "app".
Now in your "app" module you can use classes from that JAR, it will be able to locate and add "import" declarations automatically and compile just okay. The only issue might be is that it adds dependency with absolute path like:
compile files('/home/user/proj/theproj/libs/thelib-1.2.3.jar')
in your "app/build.gradle".
Hope that helps!
I solved this issue by fixing some paths in settings.gradle as shown below:
include ':project-external-module'
project(':project-external-module').projectDir = file('/project/wrong/path')
I was including an external module to my project and had the wrong path for it.
I had this issue when I manually pasted google-play-services_lib into my project. Obviously, play-services didn't have a build.gradle file in it. The solution, I learned, is to put this dependency in my project's build.gradle (instead of hard-copying the play-services directory):
compile 'com.google.android.gms:play-services:4.0.+'
When i import my library manually i had same issue. I tried to add my library with file > import module and it solved my issue.
In my case I received this error when I misspelled the module name of the library (dependency) in build.gradle file.
So remember to check if the name of the module is correct.
build.gradle
dependencies {
compile project(':module-name-of-the-library')
}
I recently encountered this error when I refereneced a project that was initiliazed via a git submodule.
I ended up finding out that the root build.gradle file of the submodule (a java project) did not have the java plugin applied at the root level.
It only had
apply plugin: 'idea'
I added the java plugin:
apply plugin: 'idea'
apply plugin: 'java'
Once I applied the java plugin the 'default not found' message disappeared and the build succeeded.
Also... check if you have the module files inside your project.
For example, I have an app which uses the Volley module. During my studies on Android development, I accidentally removed the files which were inside the "volley" directory..
~/git/Sandbox/android/HelloWorld/volley $ ll
total 8
drwxrwxr-x 2 ivanleon ivanleon 4096 Jun 16 22:26 ./
drwxrwxr-x 6 ivanleon ivanleon 4096 Jun 17 01:51 ../
I just cloned the project (see bellow) and then, I made the Sync of the project at Android Studio (Tools > Android > Sync Project with Gradle Files), and Gradle build finished normally (Gradle Console: bottom right corner of Android Studio) ;).
~/git/Sandbox/android/HelloWorld/volley $ git clone https://android.googlesource.com/platform/frameworks/volley
Cloning into 'volley'...
remote: Counting objects: 164, done
remote: Finding sources: 100% (164/164)
remote: Total 3222 (delta 307), reused 3222 (delta 307)
Receiving objects: 100% (3222/3222), 1.22 MiB | 114.00 KiB/s, done.
Resolving deltas: 100% (307/307), done.
Checking connectivity... done.
~/git/Sandbox/android/AndroidGetJSON $ ls volley
Android.mk build build.xml pom.xml
proguard-project.txt src bintray.gradle build.gradle
custom_rules.xml proguard.cfg rules.gradle volley.iml
Your build.gradle for the module/library could be as simple as:
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
If your module is just a collection of .java POJO classes.
If it's model / entity classes and you're using annotations and have some dependencies you could add those in:
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
repositories {
mavenCentral()
}
dependencies {
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-jdbc:4.48'
}
This happens when you are compiling imported or copied folder/project as module in libraries folder. This issue was raising when I did not include the build.gradle file. when I added the file all went just fine.
For me it turned out to be an relative symbolic link (to the referenced project) that couldn't be used by grade. (I was referencing a library). Thats a pretty edgy edge-case but maybe it helps someone in the future.
I solved it by putting a absolute symbolic link.
Before ln -s ../library after ln -s /the/full/path/to/the/library
I also faced the same issue and it resolved by changing one flag (gradle.ext.set("allowLocalEdits", true)) to false in settings.xml.
For me, one of dependent library does not exist in correct path, but the error message does not point THAT library correctly.
For example, what I missed is :library-3 but the error throws at :library-1.
poor gradle.
Try adding Volley library and sync and run the program. if one has pulled and i has volley usage and the error shows as -Android Studio Gradle Configuration with name 'default' not found then follow the step of adding the volley library in your gradle. hope it helps. I cleared my problem this way.

Categories

Resources