How to create a subpackage in android studio - android

I am new to Android Studio.
Right now, my android Studio project only has a single package, the application package. How do I create a subpackage ?
Currently, the package for the MainActivity.java is:
package com.davidgassner.plainolnotes.;
I want the directory for the subpackage to be: packagecom.davidgassner.plainolnotes.data;
When I created the subpackage using your's and Android Studio's instruction
I got the following:
package com.davidgassner.plainolnotes.com.davidgassner.plainolnotes.data;
I am getting an indication from Android Studio that the above path is not correct.

Right click in your main package -> New -> Package -> Give a name to your package and there you go.
If your main package is com.davidgassner.plainolnotes and you want to create com.davidgassner.plainolnotes.data , follow the steps above and when asked to input the package name, supply only "data". It will be created like this:
+ com.davidgassner.plainolnotes
+ data
In the top left corner you can switch your perspective from Android to Project to see all your project structure:

Related

Rename package com.abb.acc to com.abb.acc.add

I want to rename package name from com.abb.acc to com.abb.acc.add (Android Studio).
Right click ----> New -----> Package, it create folder out side the file
expecting get result like - package com.abb.acc.add
If you mean, you want to change file from package com.abb.acc to com.abb.acc.add, then just change the package line on top(in the file) to package com.abb.acc.add. Then press alt-enter and select move to package 'com.abb.acc.add'.
If you want to rename your entire package, then right-click on your package, select Refactor -> Rename...
Right click com ----> new ----> package, enter new package name without com
Right click previous package name > Refactor > move to new package
Move package com.app to another package
Then delete the old package
I have solved by this way

Run vanilla JUnit tests on individual classes in an Android Eclipse JUnit project

I'm pulling my hair out trying to run a plain vanilla JUnit test on my Android project. I want to write a test for a POJO class that does not use any Android objects. In fact, I can't even get a test working that tests nothing!
I've read Google's "Testing Fundamentals" documentation, countless SO questions, and I think I've achieved a new height of stupidity, as I seem to have got less far than anyone in the history of Android.
My best guess at what I should be doing is this:
Create a new android project. I have already developed my prototype application with activities, POJOs and everything else - it runs fine on my phone. "MyExample"
In the Eclipse "Package Explorer" window, In the android project I want to test, in the "src" folder item, I right-click on the package item: "com.example.myexample", select "New" > "Other...",
Then in the popup window, select "Android" > "Android Test Project"
In "Project Name" text box, I enter "TestMyProject" and hit the "Next" button.
Select the "An existing Android Project" radio button, select "MyExample", and click the "Finish" button.
In "Package Explorer", expand "TestMyExample", right click on the package "com.example.myexample.test, select "New" > "JUnit Test Case".
In that popup window, enter name "MyTestCase".
Then I enter the following in the java file:
package com.example.myexample.test;
import junit.framework.TestCase;
public class MyTestCase extends TestCase {
public void testHelloWorld(){
assertTrue("Hello World Error", false);
}
}
Finally, I right-click the file in the package explorer, select "Run As" > "JUnit Test", then in the popup window, select "Use configuration specific settings", and select "Eclipse JUnit Launcher" and hit the "Ok" button.
I get this error in the console window:
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:136), pid=5216, tid=2756
# fatal error: Invalid layout of preloaded class
I seem to be getting a variety of "Invalid layout" errors depending on what procedure I use.
Please help!!
Unless there's a typo in your question, one possible problem is the way you are trying to run them.
Select Run As -> Android JUnit test instead of just JUnit test.
That's because these tests need to run on device, so the build is slightly more involved than for normal JUnit tests.
I'm guessing you've already read the docs, but it's an easy thing to miss.

IBM Worklight 5.0.5.2 - How to change the Android package name

In worklight it seems that the android package name is set by the varible ${packageName}.
Where is this variable set? And how can I change it?
Right now the default seems to be com.applicationName. In the app im working on, this package name already exists in Google Play, so I would like to change it to com.corperationName.applicationName.
I know I can do this via Ant during Android project compilation, but I was wondering if there was somewhere within Worklight I can do this.
I was able to do this for Shell and Inner projects by making the following changes to the Shell project (check in or backup the shell and test before committing changes):
Add the following dir structure to the ShellApp/android/native/src
directory: com/corpname/{$appName}
Copy the contents of the ${packageDirectory} directory into the new
{$appName} directory (for me it was
${appName}.java.wltemplate.wluser, ForegroundService.java.wltemplate,
GCMIntentService.java.wltemplate).
In the files copied, every reference to ${packageName} needs to be
replaced with com.corpname.{$appName}
In AndroidManifest.xml.wltemplate.wluser, every reference to
${packageName} needs to be replaced with com.corpname.{$appName}.
Remove the ${packageDirectory} from the project.
Every inner project created from this Shell project should now have the package structure as com.corpname.appname

specify R package path (Android)

Is it possible to specify the package path for R.class ?
The R class package is using the package path specified in the AndroidManifest.xml
The reason I ask that because I am trying to deploy the same codebase to different application.
The difference between the apps will be the image and text. while code logic remain the same.
To deploy the same code to multiple apps require unique package name for each app in the AndroidManifest.xml.
The problem is when the package name change, R is regenerated. All java file import for R is invalid with the outdated package. And I have to modify each java file for the R.class import. If I can specify a common path for R. This problem will be solved.
You no need to go every screen to change import com.packagename.R.
1) press ctrl+h
2) Select "File Search" tab and enter your old packagename to search
3) Press "Replace" button
4) Give your new package name to replace with.
5) Clean build and enjoy.
If your using Linux machine single command do a trick
find yourprojectpath -type f -exec sed -i 's/com.oldpackage.name/com.new.packagename/g' {} \\;

Queries regarding 'backport-android-bluetooth'

I have started working on android just 1 month back (so please consider my question even if it looks simple). I have my Bluetooth code running on Android 2.2. So I am working on using backport-android-bluetooth to migrate it to Android 1.6 (as I have some old pads with 1.6).
I came across foll. link: http://code.google.com/p/backport-android-bluetooth/
I have queries regarding point no. 1 and 2 under 'Install' which are as follows:
1. download backport-android-bluetooth2.jar, and put into your projects's reference libraries. - Where is exactly 'projects' reference library'? How to put .jar file in that 'reference library
2. put backport_android_bluetooth.properties in to your src directory. -Is this file to be put in 'src' folder or '*Project_Name*' folder like project.properties file?
Thanks in advance.
Put a new file into your src dir,named backport_android_bluetooth.properties
and then put the code below in it:
#permission_name = ${your package name).PERMISSION_BLUETOOTH
permission_name = com.example.bluetooth.PERMISSION_BLUETOOTH
#request_enable = ${your package name}.action.REQUEST_ENABLE
request_enable = com.example.bluetooth.action.REQUEST_ENABLE
#request_discoverable = ${your package name}.action.REQUEST_DISCOVERABLE
request_discoverable = com.example.bluetooth.action.REQUEST_DISCOVERABLE
if u r using eclipse than right click on ur project New/Folder,
give folder name as libs and copy & paste android-bluetooth2.jar in libs folder.
than right click on libs folder go to Build Path/ Configure Build Path
Click on Add Jar, select your project/libs/android-bluetooth2.jar
press ok

Categories

Resources