Showing posts with label Android Development Problems. Show all posts
Showing posts with label Android Development Problems. Show all posts

Saturday, June 4, 2016

Renaming Android Studio Project and Main Package

Content of this blog post has been tested with Android Studio 2.0.

Changing Project Name
  • Open Project Window (View → Tool Windows → Project or Alt + 1)
  • By default Project window shows the Android view change it to Project view with the drop down menu at top left. 


  •  Right click on project root → Show in Explorer.
  • Close Android Studio.
  • Go into project folder.
  • Change .iml file to new name that you want to have for the project.
  •  Change the project folder name to new name which is same name of .iml file.
  • Start Android Studio
  • Click on “Open an existing Android Studio project”
  • Find & select the renamed project, then “Ok”
Changing Package name
  • Right Click on package name (I tried this on main package)
  • Refactor
  • Rename
  • Rename Package
  • Type new name & click Refactor
  • Click on Do Refactor 
After doing this I have observed changing the main package name successfully renamed other two packages (androidTest & Test) during refactoring process. Although Generated files like AndroidManifest.xml also had correct values strings.xml file had old project name for the string element with attribute “app_name”.
Above experiment was done on a very small project.


Tuesday, July 21, 2015

Include HttpHeaders to Google Cloud API call request made from Android

When making Cloud Endpoint API call request from the Android client sometimes it's needed to add Http Headers to that request. This blog post say how to add Date http header to request that calls myApi.sayHi() method which is described here. Read the code of EndpointsAsyncTask class. The code where http headers must be set is shown below.



MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                    new AndroidJsonFactory(), null)
                // options for running against local devappserver
                // - 10.0.2.2 is localhost's IP address in Android emulator
                // - turn off compression when running against local devappserver
                .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
                // end options for devappserver

            myApiService = builder.build();



Now add the Date http header as below. The bold text are the code that is used to add http header to request.



                MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                        new AndroidJsonFactory(), null)
                        // options for running against local devappserver
                        // - 10.0.2.2 is localhost's IP address in Android emulator
                        // - turn off compression when running against local devappserver
                        .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                        .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                            @Override
                            public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                                abstractGoogleClientRequest.setDisableGZipContent(true);


                                Calendar calendar = Calendar.getInstance();
                                SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");

                                HttpHeaders headers = abstractGoogleClientRequest.getRequestHeaders();                                Log.d(TAG, "Date: "+dateFormat.format(calendar.getTime()));
                                headers.setDate(dateFormat.format(calendar.getTime()));
                                abstractGoogleClientRequest.setRequestHeaders(headers);
                            }
                        });

                myApiService = builder.build();

Saturday, June 20, 2015

Rendering Problems: The following class could not found

Problem

In android studio, after a project was created a message was displayed with following content.

The following class could not found: android.support.v7.internal.widget.actionbaroverlaylayout


Solution

Buld > Rebuild Project

Go to build menu then rebuild the project.

Wednesday, April 22, 2015

NAND: could not write file Error

Error:

NAND: could not write file /tmp/android-nipun/emulator-kOjnli, File exists

Solution:

The hard-disk partition which has /tmp folder had not enough space when the Android virtual device (AVD) was started. Making free space that is more than needed by AVD resolve this error.