Add test package to existing Android Studio project - android

I have an existing android app and I'm trying to implement some junit tests. Normally (with Android Studio 1.2) the test package is created automatically. If I try to manually create folders to mimic the structure I've seen elsewhere there is either no option to create package under those folders, or I can't name it what I should be able to without it being placed under the existing package. Anyone know how to properly add this just as it would have been when auto created?
Every article covering this assumes its already there... like this one:
http://evgenii.com/blog/testing-activity-in-android-studio-tutorial-part-1/

This may not be the best way to do this, but I just created a new project, let it auto-generate the test package, and moved everything from my old project into the new one. There were a few references after the refactoring that needed to be cleaned up but it worked quite well for the most part.

Related

Disabling a particular package inside app/java folder in android studio

I'm not sure if this is possible in Android Studio. But how can i disable a particular package that i made inside the app/java folder?
I want to disable my dagger package because i want to make a new one for experimental purposes. But i don't want to delete the previous package so i still have a reference (for viewing purposes only).
Why not to use version control? Just make new branch for testing with new content of dagger package and clean everything there. You will have master branch with original content of that package and created branch with empty package for experiments.

Android ActionBarCompat Not working from the start

OK, I have been wanting to try the new ActionBarCompat, however, I am not able to run my programs in the emulator.
I have been trying to implement the following: http://antonioleiva.com/actionbarcompat-how-to-use.
and have been stuck on basically the first part. However, working with the author of that content, I was able to get further as I was not adding the project under sdk\extras\android\support\v7\appcompat folder like stated. However, I still think that might be the reason I cannot do this...
More detail can be found here: http://antonioleiva.com/actionbarcompat-how-to-use/#comment-43
Basically, on my first attempt, I just created an Android project, and changed the source code as indicated. Code would not run on the emulator. So I went back to the original code, and that ran on the emulator.
Checked online, found out I might need to add the \extras\android\support\v7\appcompat folder as a library to the project I am building. So I added that and a new android project was created. There were build errors from the start, but I failed at trying to add it as a library to my project, and deleted it....thinking this was way overboard.
After back and forth chats with author of linked website, I found out I had to do that overboard thing.
So I tried the following link to the T: (I cannot post more than 2 links due to low repuation...I will add this link as a comment below)
However, Eclipse would not allow me to add the appcompat Existing Android Project...but it did allow me to add the appcompat Existing (General) Project. I think this may be some of the problems??
Right now, I cannot run the project at all. Eclipse is showing a red exclamation mark on the project folder, but all the code seems to be fine. So I don't know what to do now...I recreated this project several times over, and this one was the one where I knew what to do...and I am still getting problems
So...
I decided to move to Android Studio...updated the IDE, updated the SDK manager to include the new support library, and other things. Created a new project, added to the build.gradle file as shown in the link provided below in the comment. I ran the ant build, and then built the project...tried to import the right things to allow ActionBarActivity, but I could not get that far.
I can import
"android.support.v7.*"
"android.support.vy.R" // and all folders within
but nothing allows me to add ActionBarActivity, and I don't know why.
FYI, I guess I would prefer a solution to Ecplise, as it seems like I actually got somewhere with it.
The best example to use is from here, and I would follow it closely. I had similiar issues when I first came across this. Problem was I misunderstood what I needed to do
http://developer.android.com/tools/support-library/setup.html#libs-with-res

how to install two instances by one apk?

I developed an app for android, but I need to install two instances of it, one for my daily use, another for debug/development, I don't have too many phones for debug, just have one phone, and don't want to debug on emulator, because it's too slow compare to real phone.
Or is there any thing we can change on APK file, then we can install it as another app, e.g. change it's package name ?
Currently, I changed the package name in code then make them to two apps, which can be installed on the same phone, but this way is not convenient. seek for simple way.
Update: is there any tool to modify package name in androidmanifest.xml directly after packaged(apk file)? then we just need unzip the apk, modify the androidmanifest.xml, zip the apk again.
You've answered the question yourself. You have to change the package name in the manifest, otherwise Android will override the old app (or can't install it, if the certificate differs).
Try changing the the name of the app in strings.xml from resource folder #string/app_name to have multiple instances of the same app. And package name must be changed so that the existing app is not overridden.
You can copy your project and change the package name in the copy.
You can use the same SVN path to apply the changes on the two projects.
Or you could automate the different builds using an ANT build.xml file with parameters. There are several examples on how to do this for Android in Google.
ref: One android application, one startup view, two icons
I would make the original app a library project and create a new project which uses the library project.
Advantage:
you can have both running as your new project should have a different package name
easily identification by overriding the app name in your new project (just add "beta" to it)
both versions can be installed on one device/emulator parallel
pretty good setup if you try to verify the update process of your app
no confusion with a version control system - renaming packages results in awful non-real changes on your development branches
Disadvantage:
you need to "uncheck" the library setting before you can release the original project
you might need to change some stuff in both manifest files which will increase the maintainability in a small manner
If you really need a market version of your app on your device, this method is the easiest one as a package rename will very probably result in worse maintainability.
edit:
You can mark a project as a library project in project preferences -> Android. After that you can link add that library project to another normal android project at the same spot, just click on the add button.

How to have different versions of an android project on the device?

I need to have different versions of my code on my device when I'm developing my android application. I want to have a copy of my latest code once in a week or so. The reason is that sometimes you make changes to the code and make it worse for a while, then after that you polish your code to include the features. So I need to have a copy of latest correctly running version of my code on the device.
I tried to change the app name, to see whether the ide deploys a new copy of my code, but it didn't work and the ide seems to be smarter than that and it replaces the app with the new name. I suspect that I need to change the package which is a little bit frustrating/risky. Anyone knows the solution?
Right now, I'm using Intellij to implement my android project but I think this doesn't matter.
You need to change the package name.
I use ant build script to do this easily. I created an ant task to rename the package name and make a build.
Typically I use svn to keep track of changes and label which ones are the ones that work then add features and use svn merge commands to combine new features with working code. Then if you want to undo something you can just roll back a revision.
The way I achieved that goal is:
- configure the original project as library
- create another project specifying a different package name in the manifest
- you also need to declare all the activities, receivers, etc with the full name in the new manifest
In that way switching the code of the original project through different branches you can create different apks and have different version of the app installed at the same on your device.
You need to change the package name, not the app name, it's pretty easy in Eclipse.
If your package name now is 'com.sina.perch', so just rename it to 'com.sina.perch1' or something else whatever in file 'AndroidManifest.xml' , which looks like:
It will be work.

how to import two same android app in eclipse .. ? either rename package name or what?

Me and my friend started building our first app on android. We started on one laptop and then copied project to another laptop too. Now we started doing our part on android separately.
Now i have to combine the work in one app, So when I tried to import the other project to my workspace, it says "Some projects cannot be imported because they already exist in the workspace" I tried changing my package name too. But even after that, the same warning comes. what to do? thanks
You need to set up some sort of repository with version control, then both of you can check out code, work on it and check it back in. The versioning system will keep track of everything, perform merges and flag conflicts for you.
Some info about Revision Control
And a list of various software
If you don't want to do version control, you can use a diff program to comnpare the two files and merge the differences. Set it up to compare, make the changes to "your" copy, and you should be set to go.
I've used ExamDiff to great success before (they have a very usable free version).
And here's a list of diff software.

Categories

Resources