I have an Android app but require to create two Different copies of it with different package names. The reason for wanting two package names is that I want to upload them to two different Stores which requires the developer to provide a different package name.
To simplify the update process and fixing the issues I thought of dividing my code to different libraries.
I have now created an android library and now want to upload it so that I can simply use the library in my projects by simply adding the line compile com.adc.aaa...
But I do not want those library to be accessible to other developers either directly of maybe through google Search. Is it possible to achieve this?
These are few links which I have visited regarding this matter
1) https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
2) https://mayojava.github.io/android/library/creating-and-distributing-your-own-android-library/
Can anyone please help.
Suposing your module in android studio is called "library" you can simply add the module to your app project locally without the need to upload it to bitray.
You can add a local module as a depedency to your project using AS or manually:
1) Using AS:
Go to File -> Project structure. Click on the app module and then depedencies, click on the plus sign and then choose 3 - Module Dependency. If you library is in the same folder as your app it'll show up there. Just select it and it will be added as a depedency like the other compile dependencies.
2) Manually
In your settings.gradle file add:
include ':app', ':library'
In your app leve build.gradle:
implementation project(':library')
If you library module is somewhere else you can inport it to your project using:
File -> New-> Import Module
Related
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));
}
I have a React-Native App that uses a video player component (react-native-video).
I've had to extend this project for Android to include the ability to load assets from an expansion file so this involved including the android.vending.expansion.zipfile project in the /java/com/ folder of the video project.
The video project sits under my main project via the settings.gradle:
include ':RCTVideo', ':app'
project(':RCTVideo').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android')
and build.gradle file:
compile project(':RCTVideo')
I now realise that I will have to add this same functionality to my separate audio component which also sits under my main project in the same way the video component does.
Rather than be re-apply the same project android.vending.expansion.zipfile to my audio component, can I just apply it to my main react-native android project and reference it in the sub-project??!
I'm a little baffled.
If I understand the issue, then you can simply create a separate module called zipfile that contains the android.vending.expansion.zipfile source. Then just include this module in each app or module as needed:
compile project(':zipfile')
I am working with android studio attempting to implement the following github within my own application
https://github.com/jhansireddy/AndroidScannerDemo
When following the instructions I add the following line to the gradle
compile project(':scanlibrary')
After adding the above i then sync the gradle and the whole project structure changes, to the point where i no longer recognise it
Original Project Structure
New Project Structure
If you havnt gathered i am fairly new to the whole android programming thing
One thought i had was that the git project uses OpenCV and it was related to this, however i have not manually installed OpenCV
You have to import scan library to bring project structure to normal. Follow these steps:
1 - Download zip from this link.
2 - Extract it and copy location of scanlibrary project present inside ScanDemoExample. In my case it is like (D:\Amrit\AndroidScannerDemo-master\AndroidScannerDemo-master\ScanDemoExample\scanlibrary).
3 - Now come back to Android Studio, select
File -> New -> Import Module
and paste copied location path from previous step in source directory which will result in module name :scanlibrary. Click on Finish to close the dialog.
4 - Now your project structure will look like image below. (You can view it by selecting File -> Project Structure).
5 - Don't forget to add dependency
compile project(':scanlibrary')
inside build.gradle file.
6 - Now your library is ready to use with your project. In case you are facing any errors try cleaning & rebuilding your project. And more often errors are import problem so try including these imports :
import com.scanlibrary.ScanActivity;
import com.scanlibrary.ScanConstants;
where ScanActivity & ScanConstants are classes present inside scanlibrary.
Let me know if you have any doubts. Happy coding!
add this depenedency in build.gradle
implementation 'com.github.neutrinosplatform:scanlibrary:3.3'
and add maven in repositories
maven { url 'https://jitpack.io' }
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
I'm creating Maven 2 archetypes for our project (Weld). I would like to be able to control which files are placed into the generated project based on the value of a property that is defined during archetype:generate. For instance, I foresee the following prompt:
Define value for groupId: : com.example
Define value for artifactId: : myproject
Define value for package: com.example: :
Define value for includeGradleSupport: : y
Based on the value of includeGradleSupport, I want to include (or not include) the build.gradle file in the generated project. If the user does not want Gradle support, I don't want to clutter up the generated project with unnecessary files.
Another example is that I might need to provide a Jetty web fragment (to activate a listener perhaps) if the user wants Jetty support.
It's all about customization of the project based on what the developer intends to use. While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.
Is there a way to control this behavior using the archetype-metadata.xml descriptor?
I personally would move the parts that can be removed/added on user request and put the into different maven profiles so u can build different part using different profiles
I can have a look into what coding it would take to enable this in the archetype plugin.
I think the primary vehicle to do this today would be to conditionally produce two different archetype artifacts during the original build. The archetype user would then explicitly use yourarchetype-withthing or yourarchetype-withoutthing.
I know this isn't perfectly what you are after and I agree that what you are asking for is a sensible use case.
While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.
This sentence made me think...
It seems like you have a default project structure.
Let's suppose it is big, has many files. Of course, you don't want to duplicate the logic and the files in a different archetype.
Now sometimes, a project has an additional behavior (related to Gradle).
This sound a typical use-case for another archetype that does not start from nothing, but that comes after the first one. I've seen several examples of such archetypes on the web. The developper triggers this archetype only if the project needs Graddle. :-)
So I suggest : create your Graddle archetype, that adds only the files relevant to Graddle.
Thanks for the info Dan !
I just looked at looked at archetype plugin source code, and http://jira.codehaus.org/browse/ARCHETYPE-58 doesn't appear to have resolved this issue.
Just created http://jira.codehaus.org/browse/ARCHETYPE-424 to track it.