This is the build.gradle file in the root of an Android Studio project with multiple modules, one of which is is an android app, ie it has the android plugin.
Code
subprojects.collect { p ->
if(p.name == "app") p.android.sourceSets.main
else p.sourceSets.main
}
Issues
First, I need to hardcode the name of the android project so I can use the different API since sourceSets is not directly exposed on a project that has the android plugin installed.
Second, android.sourceSets.main does not return a regular SourceSet, it returns a DefaultAndroidSourceSet which is a completely different type. I haven't found a way to convert.
Any ideas how to solve the second issue? Would also be nice to solve the first one but it's not as important. Thank you.
Related
I'm using Databinding with one of my project with project name com.abc.def. I've related all my views with binding like
ActivityLoginBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
it worked fine but if I change my package name to com.Abc.Def it generated following error at the time of building Apk.
Cause: couldn't make a guess for
com.Abc.Def.databinding.ActivityLoginBindingImpl .
Please Note:
I have an old build with com.Abc.Def on playstore already live and I'm updating the version. That's why I have to Change package name.
I can't remove Databinding from whole project.as it relates to all views.
If I change my package name to old one ,it works fine.
I have already tried clean , rebuild and invalidate cache and restart .but no luck.
I just bumped into the same issue. I was able to fix it by toggling databinding.enabled inside Build.gradle (Module). Below is a little step-by-step guide, that I went through after renaming my company package (com.abc.myapp -> com.xyz.myapp), which got databinding to work as expected:
Build > Clean Project
go to your Build.gradle (Module) and disable databinding:
android {
dataBinding {
enabled = false
}
}
File > Sync Project with Gradle Files
Build > Rebuild Project (no surprise: you'll get a ton of error messages)
Now enable databinding again:
android {
dataBinding {
enabled = true
}
}
File > Sync Project with Gradle Files
Build > Rebuild Project
Note: Some steps here may be unnecessary, but a little extra sanity checking has never done any harm during project setup, right!?
According to JAVA package naming conventions:
The package name may contain uppercase or lowercase letters[a-z], numbers, and underscores [ _ ].
You can not use capital letters in naming packages.
com..Abc.Def.databinding.ActivityLoginBindingImpl .
Check if there is no empty package there, for those ..
first of all, did you changed package name only in Manifest?
note that it could be different to applicationId - so you can only change it and leave app package as it was.
RCA: probably OS you are using to build is case-insensitive but java compiler is - that's reason why it can't find classes. Bindings are generated alongside other generated classes (for example dagger 2 classes generated by annotation processor), each generator creates own files within folder structure that reflects class package BUT if packages differ only with big/small letters, second generator will use same folder with wrong name. The reason is if OS is case-insensitive it assumes that folder already exist but java compiler not.
Other solution (except leaving app package as it is) is to :
rename all packages in app to other that differ to app package or to
use OS that is case-sensitive (macOS could be formatter this way or
linux)
I had the same issue, After spending several hours had to change the name of the layout to make it work.
Steps I followed to make it work.
Tried clean build, invalidate cache, enable/disable binding. ( didn't work)
Got a suggestion from one of my fellow developer to recreate and rename the XML file. (It worked) !!
I`ve encountered this one also. If ever Basti Vagabond Instruction did not work try to search the entire files.
Just Follow this instruction below:
Edit->Find->Replace in Files (then search the old package name and replace it with your new package name).
I made an androidLibrary project which contains some Volley request classes,
and want to write a unit test for some of these requests.
I have done that like a hundred times, and it works somehow after several tries, but never on the first try.
If I try this via androidStudio
RightClick Project->New->Android Resource Directory
you can choose between sourceSets "main", "debug" and "release". There is no androidTest option.
If I try it manualy, adding the following folders [moduleName]/src/androidTest/res/raw
and put a file inside (lets say image.jpg), I do not get the reference via R.raw.image. In fact I haven't access to R.raw in my Test at all.
I also tried a Build->rebuild project or Build->clean without success.
In other projects I have a my.app.namespace.R along a my.app.namespace.test.R which holds all test resources.
So my question is:
What do I need to do in order to add a res folder to my androidTest, which is accessible via R.[folder].[resId]?
Am I missing a crucial step after adding the files (i.e. telling gradle explicitly about it)?
Because adding a tag like this in my build.gradle also doesn't seem to make any difference:
android {
sourceSets {
androidTest {
java.srcDirs = ['src/androidTest/java']
res.srcDirs = ['src/androidTest/res']
}
}
}
If it matters I am using:
Android Studio 3.1.2
gradle-wrapper 4.4
minSdkVersion 19
targetSdkVersion 27
I figured out what is going on with the help of the update of Michael Krussel Answer:
Android Studio is not compiling the my.app.namespace.test package automatically. All you need to do is run the Test the first time, ignoring the errors AndroidStudio might present.
After the first run you got access to the whole test namespace (including the *.test.R class)
No additional gradle config (like sourceSets from above) are necessary!
I want to deploy PhoneGap app on the Android simulator provided with eclipse. I decided to use Dojo Toolkit which heavily relies on the " _ " convention (starting a file/folder with " _ " means this is a private/internal module).
Basically the problem is that while deploying the app, every file/folder starting with "_" is omitted. This completely messes things up, Dojo toolkit as exptected fails to work.
Is there a way to fix this?
aaptOptions{
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
add the above lines in the application build.gradle file inside android block for android app
First go star this issue so Google will fix the bug eventually. If you are running on Mac or Linux there is a patched aapt that fixes the bug here. Other than that your only choice is to do a build of Dojo so that it is only in one file.
From the previous answer I ended making changes on ant.properties which is located at root of project with this:
aapt.ignore.assets=!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~
Here, I overwrote aapt.ignore.assets property defined on sdk-android directory. It works
For any Dojo developers out there, or anyone having issues with this in general.
What fixed it for me in Android Studio is opening the build.gradle, then adding to the android block:
android {
compileSdkVersion 26
...
aaptOptions {
ignoreAssetsPattern '!._'
}
}
A work around is to use dojo.js from the CDN
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.9.0/dojo/dojo.js"></script>
Also, I started looking for a minify app or service, which could create a single file from all the required dojo files, but did not find one easily.
I am having an Android Studio project, that works perfectly fine with Windows and is stored in Mercurial repository. Importing it on Windows can be done without any issues, yet on Linux everything crashes, as modules cannot be read correctly - AndroidManifest.xml is apparently missing.
I am aware of other threads and I have searched for suitable solution, but I am afraid that so far I haven't managed to fix the problem.
It is very important to me, that the project is set up correctly and whenever new person clones the project it will work without issues (and without necessity of recreating the project from scratch) regarding the operating system.
The current build.gradle file in failing module is already pointing to the correct location of manifest file:
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
Yet I am still having the following error:
Error:/AndroidManifest.xml (No such file or directory)
Im am on a Mac so I don't know if it's the same, there should be two tags to the left of your code, just beside the name of your class, something like :
<> public class missingFile {
if u click on those tags, suddenly Android Studio will give you an option to open your xml file.
I hope it helps, goodluck
Long-time Eclipse-ADT user, and I've started looking into Android Studio since most samples on the web are now built with gradle. Now I just recently installed Android Studio on my machine and am trying out the samples from developer.android.com, specifically this one: FloatingActionButton
I imported the project in Android Studio, run it on my Nexus 5, works fine. The FABs are rounded and has drop shadows and all.
Now out of curiosity I tried to build the same project in Eclipse. So I fired up Eclipse, created a new project, copy-pasted everything from the Application folder into their proper destinations, then run the project on the same device.
The buttons are square.
Looking into the code, the following lines are responsible for giving the buttons a round shape are as follows:
Under FloatingActionButton.java
setOutlineProvider(new ViewOutlineProvider() {
#Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, getWidth(), getHeight());
}
});
setClipToOutline(true);
Now question is, why does these snippets of code work on Android Studio but not in Eclipse?
It is most likely related to which dependencies are in your project.
Using Gradle, you can configure wildcards for dependency version numbers, meaning that your project will always have the latest version of that library (for better or for worse)
With Eclipse-ANT you are most likely using manually downloaded and imported libraries, of a static version number. And the particular version you are using is compiling square buttons
Finally got it to work. The issue is that the AndroidManifest.xml that i copied over from the Application/src/main folder does not have a min SDK and a target SDK version -- both of which are defined in the build.gradle file, in the /Application directory. I added both and the FABs are now rounded with shadows and all.
Since I can't give bounty to myself, I'd give it to the answer who can explain further, or at least point to something that documents this change.
Now in AndroidStudio you can specify the most of the manifest configuration in build.gradle it will first refers to the module's build.gradle for this configs it is helpful and required for many things one i know is as follows.
Android studio and gradle gives you many new features one of them is buildtypes and flavours using which you can create a new flavours of your one project with very much less efforts, see in eclipse you need to create a whole new project for another flavour of your project while in android studio you can do it in single project. See when you define another flavour you can also define some of the manifest properties that will apply only to that flavour like you can change project name, package name, min sdk, target sdk, version, permission and so on.
There will only will be one manifest so if you declare multiple flavours and define this kind of changes than build.gradle file will fetch that changes and applies to the manifest specifically for that flavour so your manifest will get updated for that flavour.