私は最初のプログラムをAndroidに移植しています。アプリケーションは単純なボタンクリッカーで、前の数字に1を加えてクリックした回数をカウントします。コードのリリース版を実行しようとすると、ボタンを押すときにクラッシュします。私はデバッグバージョンに問題はありません。 gradle.buildAndroidアプリはデバッグでは動作しますがリリースではありません
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'austin'
keyPassword 'Austin42'
storeFile file('D:/key.jks')
storePassword 'Austin42'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "austinhenley.clicker"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
multiDexEnabled true
versionName "1.0"
signingConfig signingConfigs.config
}
buildTypes {
release {
minifyEnabled false
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
wearApp project(':wear')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
}
私はリリースバージョンでデバッガを実行することができました
と、この:ここ
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView text;
Button adder;
Button reset;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.text);
adder = (Button) findViewById(R.id.button01);
reset = (Button) findViewById(R.id.button02);
}
protected void add(View view)
{
int count;
count = Integer.parseInt((String) text.getText()) + 1;
text.setText("" + count);
}
protected void reset(View v)
{
text.setText("0");
}
}
はXML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="person.clicker.MainActivity">
<Button android:id="@+id/button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:onClick="add"
android:layout_above="@+id/button02"
android:layout_centerHorizontal="true"
android:layout_marginBottom="59dp" />
<Button android:id="@+id/button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="reset"
android:onClick="reset"
android:layout_marginBottom="136dp"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/button01"
android:layout_alignStart="@+id/button01" />
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="49dp" />
がUPDATEでありますボタンを押すと何が起こるか
E/AndroidRuntime: FATAL EXCEPTION: main
Process: austinhenley.clicker, PID: 31983
java.lang.IllegalStateException: Could not find method add(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'button01'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22433)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6126)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
スタックトレースを教えてください。 –
クラッシュログはありますか? Crashlyticsをインストールしましたか? –
stacktraceとgradle buildtypesの設定を投稿してください –