Android Module reference layout error - java

I'm not good at using the modules on Android
So I have a problem. When I called module activity it must refer the module layout but actually it's referring to the App layout.
I guess it might R.java problem, but I'm not sure.
Here is how it is setup in my project.

During the build process, any resources in a library module are ignored if the same resource appears in the main module. That's why androidmodule2.MainActivity is picking up the activity_main layout from the app module: the resource of the same name in the library module is being thrown away during the build process.
Change the name of the layout resource in one of the modules so there's no name collision and all should then be well. (Well, at least this particular problem should go away.)

Related

Looks like android studio can't find classes from dependency

I wanted to make settings fragment for my app so I added preference dependency to my build.gradle
def preference_version = "1.1.1"
implementation "androidx.preference:preference:$preference_version"
implementation "androidx.preference:preference-ktx:$preference_version"
but when I want to use any class from this library in XML Layout like for example
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreferenceCompat
app:key="notifications"
app:title="Enable message notifications"/>
<Preference
app:key="feedback"
app:title="Send feedback"
app:summary="Report technical issues or suggest new features"/>
</PreferenceScreen>
I'm getting errors:
Cannot resolve class PreferenceScreen
Cannot resolve class SwitchPreferenceCompat
Cannot resolve class Preference
I tried to build project after using /gradlew clean but nothing helped, I tried to use different versions of dependencies, different versions of gradle and use only dependency for java and only dependency for kotlin multiple times with different configurations but nothing helped. What is strange outside of XML files everything seems to work just fine and I can use classes from this library just fine, but I need to make layout with PreferenceScreen class and it's not recognising it.
Did you put the xml file under the "xml" folder?
It must be placed under "xml" folder not under "layout" folder
You have to use a PreferenceActivity and call the file with:
addPreferencesFromResource(R.xml.settings);
Official documentation: https://developer.android.com/guide/topics/ui/settings

AnnotationTypeMismatchException in Butterknife #BindView with layouts defined in another folder structure

While working on a project recently, As the layouts was adding up so many xml's, I added subfolders to layout resources to make the project structured, But after that ButterKnife Injections are not working. I am getting the following error.
#BindView(R.id.tb_tvcoinsMainCommon) TextView tvCoins;
^
java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract int butterknife.BindView.value() (Found data of type <any>)
findViewById() is not giving any issues, only ButterKnife Bindings are giving issues. If anybody has a solution that would be helpful
Thanks for looking into this, the issue was the code was not able to find the xml files from the new layout directory.
The build.gradle file was missing the correct resource folder configuration. The gradle file and the project structure looks like this after solving

Eclipse asking for module named after the old project name

I'm trying to make my project modular on Eclipse, but I'm running into an issue. I have added the module-info.java file through right-clicking on the project > Configure > Create module-info.java. However, when I run, I get the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module serenitea-pot-manager not found
I believe this might be caused by having renamed the project to sereniteaPotManager at some point. Initially, the project name was serenitea-pot-manager, which is the name of the module being asked for. I did the renaming through right-clicking on the project > Refactor > Rename..., which should have updated all instances.
I have been searching for a while, but still haven't found a way to fix this. Is there anything else that I need to update on Eclipse for it to change to the correct module name?
Note: The module name included in module-info.java is indeed sereniteaPotManager.
I had the same problem. I will summarize my experience then my solution.
I did a rename of the module, and Eclipse kept wanting to use the old module name. Cleans, restarts, etc., did not help. A search of the project properties, the run configuration, and all files in the workspace, did not turn up an instance of the original module name. Editing the module name so that it matched the original one did work. It is as if Eclipse tucks away the initial module name in some hidden place and keeps wanting to use it.
I was able to solve the problem by deleting all Run configurations that existed and then creating a new project and new Run configuration.
I am using JavaFX, and a somewhat peculiar side-effect of this is that the normally-required run configuration argument (below) was not needed in this new run configuration. I wonder if Eclipse is tucking that away in some hidden place, also?
In Java, serenitea-pot-manager is an invalid module name since a module name must not contain hypens (-).
Therefore, In module-info.java, Eclipse shows Syntax error on token "-". So make sure, before running your application, no compile errors are shown in the Problems view.
Rename your module to serenitea_pot_manager, delete the existing launch configuration (in Run > Run Configurations...) and try again:
module serenitea_pot_manager {
// ...
}
https://stackoverflow.com/users/17416717/stevevzzz[Steves] solution worked for me while I got stuck with the same problem.
... but I did not create a new project. I only was able to solve the problem by deleting all Run Configurations that existed and then I created a new Run Configuration.
I noticed the same behaviour. After changing the module name of my project, I got the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module ... not found
It looks like eclipse holds on to the original module name that is used when first running the application using the Run Configuration. To work around this issue, I deleted and recreated the run configuration. Then it works again.

How to use a project in another project as a module?

I'm hoping to modularize an Android project so it will be easy to maintain in future use. I want to know whether its possible or not, to make an Android project used as a module within another Android project?
For example, let's say in my main android project I have three buttons for login, signup, forget password. and I have three separate projects for login, signup and forget password with their own views, activities and libraries. How can I use these separate android projects in the main Android project so when I click any of the three options in the main activity view so it will load the relevant view from those three module projects? (click the login button in the main view and load login view from the separate login project activities). I have tried to fiddle with build files and library module importing but couldn't do it. help me with saying if this approach is possible or not? if possible how to achieve it?
settings.gradle in root project include each project.
include ':loginApp'
include ':signupApp'
include ':resetpasswordApp'
project(':loginApp').projectDir = file('path/to/LoginApp')
project(':signupApp').projectDir = file('path/to/SignupApp')
project(':resetpasswordApp').projectDir = file('path/to/ResetpasswordApp')
build.gradle Of main module
implementation project(':loginApp')
implementation project(':signupApp')
implementation project(':resetpasswordApp')
Yes, it's possible.
Your current project is basically a module too. See the app folder.
An easy way is to create a new module (android library) with a different name from the current one which by default is app. Let's call it bigapp. This module will have all properties just like your app and you can select to run it from the debug configuration too.
Go to settings.gradle and ensure the file reads include ':app', ':bigapp'
To use the bigapp and call its functions, import it in your dependency. This will be the build.gradle file of the app module.
dependencies {
implementation project(":bigapp")
}
Lets now start the MainActivity from our app module
startActivity(new Intent(this, com.lucemanb.bigapp.MainActivity.class));
You can also import it at the top and simply call the MainActivity
import com.lucemanb.bigapp.MainActivity;
---
private void startActivity(){
startActivity(new Intent(this, MainActivity.class));
}

ClassNotFoundException when using library projects

I have a problem when trying to reuse a project class and resources, I always get a ClassNotFoundException. I dont know what I'm doing wrong.
The easier steps for reproduce my problem is create this two projects:
MyLibrary project:
Creating a example launcher activity ("Activity1") and in properties/Android
section mark as librayy
MyProject project:
It is just an empty project (no classes), in Java Build Path\Projects tag add the
project "MyLibrary" and declare in the manifest that it MAIN & LAUNCHER activity
is "Activity1"
Press play and there you have the ClassNotFoundException.
My target is inherit a whole project for making a free version from a paid version and keeping the common code in a single place for keep the maintain easy
Thanks

Categories