How to completely rename a project in Android Studio - android-studio

The old project name was expense_calculator.
Then I renamed the project to a different name, but somewere the old name still present, so when I import a package in Android Studio it substitutes the old name in imports, like
import 'dart:io';
import 'package:downloads_path_provider/downloads_path_provider.dart';
import 'package:expensecalculator/models/entry.dart';
import 'package:expensecalculator/models/entry_list_model.dart';
import 'package:flutter/material.dart';
...
How can I change all of the names throughout the whole project?

You have to change the package name parameter in the pubspec.yaml file to whatever new name you want. Then the imports will use the new name.

Related

Importing PocketSphinx resources into Android Studio

I am trying to start a project using PocketSphinx resources. What is the method for importing PocketSphinx resources into my Android Studio workspace?
import edu.cmu.pocketsphinx.Assets; //"unused import statement"
import edu.cmu.pocketsphinx.Hypothesis; //"unused import statement"
import edu.cmu.pocketsphinx.RecognitionListener; //"unused import statement"
import edu.cmu.pocketsphinx.SpeechRecognizer; //"unused import statement"
import edu.cmu.pocketsphinx.SpeechRecognizerSetup; //"unused import statement"
public class MainActivity extends AppCompatActivity implements RecognitionListener {...
As expected, I am getting a, "Cannot resolve symbol 'RecognitionListener' " on the last line. Thanks in advance.
The library is distributed as an Android Archive (AAR). Download from https://github.com/cmusphinx/pocketsphinx-android-demo/blob/master/aars/pocketsphinx-android-5prealpha-release.aar
Move pocketsphinx-android-5prealpha-release.aar into helloworld/app/lib/ directory.
In Android Studio go to File > New > New module, scroll down and choose Import .JAR/.AAR Package. Browse to /app/lib and select the .aar file. Click "Okay". Keep the apps module selected, click dependencies tab, click "+" on far right side, choose "Module Dependency". Select Module and click "Okay". For further information go to How to manually include external aar package using new Gradle Android Build System, scroll to Oliver Kranz's answer for nice screen grabs of the process.

How can I set up an alias for imports in Python?

I want my project to work in two different situations. It should work as a standalone library, but also as sub package of a larger project. The main use case is that of a standalone library, where its internal imports should be of the form
from my_library import sub_package
When using the code as sub package of a larger project, these imports don't work as there is no global name my_library. Instead, I would have to use relative or absolute imports, for example
from large_project.my_library import sub_package
Let's assume I wrote my library as shown in the first example. How can I overwrite importing behavior when running as part of a larger project to automatically adjust import paths?
Thanks to #MatrixTai's suggestion of adding the parent directory of the package to the the module path, I came up with this dynamic solution. At the top of my_library/__init__.py:
# Make package global even if used as a sub package to enable short imports.
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
We have to navigate up two directories here to do from the my_library/__init__.py to my_library and from there to its parent direction, where imports will find the library.
You don't have much choice.
If you want to reference the my_library.py anywhere, there is 2 method (as I known) can do similar work.
1: add system path. Like those module you installed by pip. pip module is installed in /Python/Scripts. You can add a new path or simply put my_library.py into one of the path. For adding, that's in Computer(right-click)-> Properties -> Environment Variable -> Choose Path and Click Edit
(Though you may not want to use this.)
2: Changing __init__.py, but still at least one line you must add in my_library.py.
For example,
/Directory
/large_project
-__init__.py #call this sub_init
-my_library.py
-__init__.py #call this main_init, this fake
-main.py
In main_init,
import sys
sys.path.append('\\Directory\\large_project')
As main_init is not executed when you execute main.py (this is fake), so in main.py
import __init__
from my_library import sub_package
But as well you can take this main_init as the starter of library, like declaring __all__, etc.

Importing AndEnginePhysicsBox2DExtension-GLES2 in Android Studio 1.5

I'm trying to make flappy bird equivalent app using AndEngine. I'm having trouble importing AndEnginePhysicsBox2DExtension-GLES2 module in Android Studio 1.5
So far, I have imported AndEngine-GLES2 as module by
Project Structures -> green + sign on left top -> import Eclipse ADP -> selecting path
to AndEngine-GLES2 source.
For some reason when I try this for AndEnginePhysicsBox2DExtension-GLES2, it doesn't recognize it as module therefore I can't import it. I'm not using JAR FYI.
step 4 in here doesn't help as I can't import AndEnginePhysicsBox2DExtension-GLES2, at all.
You have to remove "-GLES2" from folders names.
Other solution could be: File -> New -> Import project -> Select AndEnginePhysicsBox2DExtension and save the project.
Then import the module from project structure...
For both libraries do the following:Go to project strukture -> modules-> button + import module from existing sources.
Then click on your module, switch to dependencies bookmark and add Andengine and physics extenstion imported modules.
Then click on Andengine project and add dependency to Physics extension module.

Imports libraries dont stay on code

When ever I start a new project to practice using Android Studio the following
imports are added by default:
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
As soon as I start adding another import to follow an example from a book or tutorial the whole new line disappears. If I add lines without the semicolon nothing happens. As soon as I begin adding the semicolons the new lines start disappearing. Why is this happening?
AndroidStudio auto "organizes" your imports. Just start adding your code and it will add the imports that you need. If you want to toggle this off, which I don't recommend, it's in: Preferences -> Editor(Under IDE Settings) -> General -> Auto Import

Python 3, imp.reload does not appear to have any effect

I am modifying a module which contains a class in it.
When I %run another module that uses the mofified class from IPython, the changes do not seem to take effect unless I restart IPython.
I have tried to use imp.reload, but this does not help. For example, I have put the following the code at the top of my module, but it does not appear to be using the updated version of my modified class (BigMySQLDatabaseGetter in the big_mysql_database_getter module)
import imp
import sys
from big_mysql_database_getter import BigMySQLDatabaseGetter
module_big_mysql_database_getter = sys.modules['big_mysql_database_getter']
imp.reload(module_big_mysql_database_getter)
Reloading a module doesn't automatically update all references that were created before, it just redefines everything within the module.
So if you do something like:
from spam import eggs
imp.reload(spam)
print(spam.eggs is eggs)
you'll get False, as eggs still references the old class. Likewise, instances created before the reload are instances of the old class, not of the new class:
import spam
e = spam.eggs()
imp.reload(spam)
print(isinstance(e, spam.eggs)) # False!
In your case, you can either reimport BigMySQLDatabaseGetter after reloading the module, or instead of directly importing the class just import the module and use big_mysql_database_getter.BigMySQLDatabaseGetter instead.

Resources