Is Androids new Jack compiler really that slow? - android

On some of my Android projects I see that building got quite slow since using the new Jack compiler. I need it to use Java 8 features like lambdas.
But the long building time is a bit disturbing. So I set up a new Android project. It contains just a MainActivity with one button which reacts on your click.
package de.xappo.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View view) {
Toast.makeText(MainActivity.this, "Button clicked!", Toast.LENGTH_LONG).show();
}
});
}
}
There is nothing else except from the layout file which just contains a a TextView and a Button within a RelativeLayout.
As you can see in the picture all the jack gradle tasks together take about 75 seconds. Is this normal? This hole example app builds in less than 22 seconds without jack. So is this big difference normal?
I already managed Java heap size within my gradle.properties file:
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Is there still any thing to do to improve jack compiling performance? Or do you know about any updates planned on jack to improve building time?

As per this announcement, the Jack toolchain on Android is deprecated and java8 support will be directly integrated into Android's standard javac and dx toolchain. I switched to Jack for java8 support, but then transitioned to retrolambda because Jack was so slow.

Related

Android studio project could not find android.view.View

My Android project show that it is not able to find the android.view.View class but still it is being compiled and run on simulator and devices.
apart from android.view.View All other class of the package is accessible like
This is not available ==> import android.view.View;
this is available => import android.view.ViewGroup;
I have tried many things like Clean, Rebuild, restart and Invalidate cache and restart but not fixed this issue.
Please check the code and help me to fix this issue.
import android.view.View;
public class AppSettingsActivity extends BaseActivity implements View.OnClickListener, AdListener {
//Other objects
private static final String TAG = AppSettingsActivity.class.getSimpleName();
//Data objects
// //Design
private LinearLayout banner_container;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
initViews();
}
private void initViews() {
//Actionbar init
//Action bar
TextView idTvTitle = findViewById(R.id.idTvTitle);
findViewById(R.id.idTvSelectDefaultActivity).setOnClickListener(this);
findViewById(R.id.idTvSelectAppLang).setOnClickListener(this);
findViewById(R.id.idIvBack).setOnClickListener(this);
findViewById(R.id.idTvCalcSetting).setOnClickListener(this);
//Set data
//Set Actionbar Title
idTvTitle.setText(R.string.app_settings_text);
//Load Facebook ads
banner_container = findViewById(R.id.banner_container);
if (fbAdView != null) {
banner_container.addView(fbAdView);
fbAdView.loadAd();
fbAdView.setAdListener(this);
logs.e(TAG, "Face book load add called....");
}
int selectedLanguage=SessionManagement.getIntValue(AppSettingsActivity.this, AppConstant.SELECTED_LANG, AppConstant.INT_ONE);
int selectedScreen=SessionManagement.getIntValue(AppSettingsActivity.this, AppConstant.DEFAULT_SCREEN_INDEX, AppConstant.INT_ONE);
String[] languages = getResources().getStringArray(R.array.language);
String[] screens = getResources().getStringArray(R.array.screens);
((TextView)findViewById(R.id.idTvSelectDefaultActivity)).setText(screens[selectedScreen]);
((TextView)findViewById(R.id.idTvSelectAppLang)).setText(languages[selectedLanguage]);
}
I am giving this answer to my question.
I simply uninstall the Android studio and reinstall it. My previous Android studio was running with 3.5 version (Latest) and the fresh install Android studio version was also 3.5 so there was no versioning difference in it. But I don't know some How issue fixed when I reinstall AS.
After half an hour of searching, I could not found a solution that can fix my issue. Then I pass the same code to other PC and it was working well on that PC.
So This is final that no issue in the source code.
Then 2nd suspect is the android studio
I uninstall Android Studio and install it again, it took me 1 hour to set-up and make the code workable but it saves 30GB of my hard disk space so it was worth it.
But still, Android studio manage SDK and build tools very badly

visual studio android import cant resolved after update

I updated Visual Studio, then my Android project had errors such as import could not be resolved. It could not be resolved to a text type. The type could not be resolved. Then I created a new project with the same settings. However, it had the same errors. It does not work because of the code, but maybe it knows who knows the code here.
package com.Android2;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class Android2 extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* Create a TextView and set its text to "Hello world" */
TextView tv = new TextView(this);
tv.setText("Hello World!");
setContentView(tv);
}
}
There is no problem with your code or imports...
I know it is hard work and a serious change when it comes to shortcuts, menus, overview, etc., but i would suggest to use android studio instead of visual studio if you only write android apps in java. I used visual studio too and switched to android studio.
Android Studio will give you more comfort than every other ide in programming android apps in java!
I know this problems you wrote about very well and had the same. Sry that this isnt a really answer of your problem and does not solves your concrete problem.
Tips for solving, you probably already know:
reboot your pc and visual studio if you not already did
delete caches or other from visual studio
rebuilt/clean your project
not easy, but reinstall visual studio
I hope i could help anyway!

Android activity & import issue

Trying out some android programming that has gone fine up until this point. I'm getting the following errors:
Activity cannot be resolved to a type
The import Activity cannot be resolved
on the top two imports (activity and bundle) of the following class:
package com.example.sqlite;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
public class Input extends Activity {
private EditText txtTitle;
private EditText txtURL;
private Button btnOK;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.input);
txtTitle = (EditText) findViewById(R.id.editText1);
txtURL = (EditText) findViewById(R.id.editText2);
btnOK = (Button) findViewById(R.id.button1);
}
}
I've done the standard ctrl + shift + O, which does automatically add these imports but the errors remain. I've also rebuilt it over and over with no effect.
Ca anyone see were I'm going wrong here?
Do right click on the project node in Eclipse and select Android Tools->Fix Project Properties. It looks like you are missing link to your Android libraries. Good way to check on that is to open properties-> Java build path -> Libraries and verify that Android link is there. If not - do Properties->Android and select project target you would like to use
You may occasionally see strange erros if any of your XML files fail to build. Check your console to see if any of your layout or resources have errors. Do the following:
Project > Clean
If this does not fix it, verify that pour souce actually exists in the project path:
com.example.sqlite
Check your manifest xml if the activity is included.. This can sometimes cause the error.

OnClickListener() must override a superclass method?

With this code:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
. . .
Button buttonAuthorizeUsers = (Button) findViewById(R.id.buttonAuthorizeUsers);
buttonAuthorizeUsers.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent configure = new Intent(OnDemandAndAutomatic_Activity.this, Configure_Activity.class);
OnDemandAndAutomatic_Activity.this.startActivity(configure);
}
});
I'm getting:
The method onClick(View) of type new View.OnClickListener(){} must override a superclass method
It would seem that this problem is sometimes caused by a Project | Properties | Java Compiler being set to 1.5.
Although I'm virtually I'd had this problem before, and changed it to 1.6, somehow it WAS 1.5 again.
HOWEVER, that (changing it to 1.6) did not solve the problem. I'm still getting that same err msg, after cleaning, building, and F11ing...???
I would recommend that you uncheck "Enable project specific settings", click "Configure Workspace Settings..." and change "Compiler Compliance Level" to 1.6 or above. Otherwise you would have to specify it every time.
If you need a specific compliance level for a specific project, you need to verify every other project that need compliance level 1.6 or above is set to this.
After everything is correctly setup - clean projects and restart Eclipse. Eclipse can be such a bitch some times - this often solves problems for me.
Two things to consider:
1) Take a look at your imports - are you sure that View.OnClickListener is imported, but not lets say DialogInterface.OnClickListener
2) OnClickListener is actually an interface, that you are instantiating anonymously. So after all when writing the onClick method you are actually not overriding a super class method, but instead implementing an interface method. Annotating interface methods with #Override is a good practice, but this has been introduced in JDK 6, which means that by the time Android 1.5 or 1.6 was developed this may not has been yet introduced to the java language and hence making it an invalid syntax.
Right below the "Compiler Compliance Level", there are a few options grayed out if the "Use default compliance settings" checkbox is checked: Namely, "Generated .class files compatibility" and "Source compatibility". Verify that both of those are set to 1.6 - If not, either change the default compliance settings, or uncheck that box and tweak them directly.
Button buttonAuthorizeUsers = (Button) findViewById(R.id.buttonAuthorizeUsers);
buttonAuthorizeUsers.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent configure = new Intent(OnDemandAndAutomatic_Activity.this,Configure_Activity.class);
OnDemandAndAutomatic_Activity.this.startActivity(configure);
}
});
try to replace this line
buttonAuthorizeUsers.setOnClickListener(new View.OnClickListener() {});
this error you got happened when your trying to assignee the On-click to unexpected type !
So, beleive me Eclipse IDE most of time will import DialogInterface instead of View so write it by your self.
daigoor is right. Eclipse always try to do this 'import android.content.DialogInterface.OnClickListener' instead of the doing this -> 'import android.view.View.OnClickListener'. That solves my problem.

Why does EditText retain its Activity's Context in Ice Cream Sandwich

In Ice Cream Sandwich, when there's an Activity containing an EditText, the EditText will retain the Activity's Context even after the user leaves the Activity. To demonstrate this I've created TestLeakActivity, which allocates a large byte array. Since the Activity's Context is never garbage collected, the byte arrays accumulate on the heap, eventually causing an OutOfMemoryError. You can observe the heap growth by using the DDMS heap tool, and you can track the outstanding references to the EditText class by looking at the HPROF file in Eclipse MAT. To create memory leaks, go into LaunchActivity and just keep launching and backing out of TestLeakActivity.
LaunchActivity.java
package com.example.testleakproject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class LaunchActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = new Button(this);
button.setText("Start TestLeakActivity");
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LaunchActivity.this, TestLeakActivity.class);
startActivity(intent);
}
});
ViewGroup container = ((ViewGroup) findViewById(android.R.id.content));
container.addView(button);
}
}
TestLeakActivity.java
package com.example.testleakproject;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.EditText;
public class TestLeakActivity extends Activity {
private byte[] mSomeBytes = new byte[1048576];
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EditText editText = new EditText(this);
editText.setHint("TestLeakActivity");
ViewGroup container = ((ViewGroup) findViewById(android.R.id.content));
container.addView(editText);
}
}
This is a known bug, that will be fixed in ICS MR1.
This has not been fixed until now. (Android 4.2.1)
I've just spend several hours to find that I'm affected by this issue.
The issue seems to be caused by the spell checker. When I disable suggestions for the EditText view everything is properly garbage collected.
mInputType = mText.getInputType();
mText.setInputType(mInputType | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
I don't really want to disable this, since many users want spell checking. So, maybe there is a way to temporarily enable it when the input field receives the focus.
If you don't need the spell checker just add this to the EditText element in your layout xml instead:
android:inputType="textNoSuggestions"
That seems to fix it too.
Edit:
Just found this thread that appears to be related: Work around SpellCheckerSession leak?
I'm experiencing the same. My Gingerbread devices all work fine, but testing on my Galaxy Nexus this situation arises predictably. What your experiencing is likely why the MR1 and 4.0.3 updates rolled out so quickly.
You are running into the situation described in the Android resources section on memory leaks. See that page for some solutions as well.
I got the same problem,
I solved it by hiding the EditText ondismiss of my dialog.
mEditText.setVisibility(View.GONE);

Categories

Resources